summaryrefslogtreecommitdiff
path: root/src/fe-common
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2001-05-17 17:07:40 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2001-05-17 17:07:40 +0000
commitfe5c94b050650c8b8f20278ea413fb1cc8d093dc (patch)
tree979ee7be59a3ef621c6088b3511cb9dcd33be246 /src/fe-common
parentccccd1fdc4fdafc9a7669734d795332f2803c407 (diff)
downloadirssi-fe5c94b050650c8b8f20278ea413fb1cc8d093dc.zip
Small speedup when pressing unbound keys.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1502 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/fe-common')
-rw-r--r--src/fe-common/core/keyboard.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/fe-common/core/keyboard.c b/src/fe-common/core/keyboard.c
index 3fdf7d97..0b7ac714 100644
--- a/src/fe-common/core/keyboard.c
+++ b/src/fe-common/core/keyboard.c
@@ -34,6 +34,10 @@
GSList *keyinfos;
static GHashTable *keys, *default_keys;
+/* A cache of some sort for key presses that generate a single char only.
+ If the key isn't used, used_keys[key] is zero. */
+static char used_keys[256];
+
/* contains list of all key bindings of which command is "key" -
this can be used to check fast if some command queue exists or not.
Format is _always_ in key1-key2-key3 format (like ^W-^N,
@@ -250,10 +254,13 @@ static void key_states_scan_key(const char *key, KEY_REC *rec, GString *temp)
}
g_strfreev(keys);
- if (temp->len > 0)
- g_string_truncate(temp, temp->len-1);
+ if (temp->len > 0) {
+ g_string_truncate(temp, temp->len-1);
- g_tree_insert(key_states, g_strdup(temp->str), rec);
+ if (temp->str[1] == '-' || temp->str[1] == '\0')
+ used_keys[(int) (unsigned char) temp->str[0]] = 1;
+ g_tree_insert(key_states, g_strdup(temp->str), rec);
+ }
}
static int key_state_destroy(char *key)
@@ -269,6 +276,8 @@ static void key_states_rescan(void)
{
GString *temp;
+ memset(used_keys, 0, sizeof(used_keys));
+
g_tree_traverse(key_states, (GTraverseFunc) key_state_destroy,
G_IN_ORDER, NULL);
g_tree_destroy(key_states);
@@ -469,6 +478,12 @@ int key_pressed(KEYBOARD_REC *keyboard, const char *key)
g_return_val_if_fail(key != NULL && *key != '\0', FALSE);
if (keyboard->key_state == NULL) {
+ if (key[1] == '\0' &&
+ !used_keys[(int) (unsigned char) key[0]]) {
+ /* fast check - key not used */
+ return FALSE;
+ }
+
rec = g_tree_search(key_states,
(GSearchFunc) key_states_search,
(void *) key);
@@ -772,6 +787,7 @@ void keyboard_init(void)
key_states = g_tree_new((GCompareFunc) strcmp);
key_combos = NULL;
key_config_frozen = 0;
+ memset(used_keys, 0, sizeof(used_keys));
key_bind("command", "Run any IRC command", NULL, NULL, (SIGNAL_FUNC) sig_command);
key_bind("key", "Specify name for key binding", NULL, NULL, (SIGNAL_FUNC) sig_key);