summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2014-02-10 21:10:45 +0100
committerSebastien Helleu <flashcode@flashtux.org>2014-02-10 21:10:45 +0100
commiteef3b570752b974b87f5b189c89813f400f55a6e (patch)
tree95bdf6baf01d714202f70980ba6af83d7ed3bbf8 /src/gui
parent437767c0ca37ab06d0f2c2ff2831c7ebe1c3e61f (diff)
downloadweechat-eef3b570752b974b87f5b189c89813f400f55a6e.zip
core: split key command when the key is created (improve speed when executing commands of a key)
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui-key.c133
-rw-r--r--src/gui/gui-key.h3
2 files changed, 67 insertions, 69 deletions
diff --git a/src/gui/gui-key.c b/src/gui/gui-key.c
index a3b83cc87..915c001d2 100644
--- a/src/gui/gui-key.c
+++ b/src/gui/gui-key.c
@@ -632,59 +632,49 @@ gui_key_new (struct t_gui_buffer *buffer, int context, const char *key,
if (!key || !command)
return NULL;
- if ((new_key = malloc (sizeof (*new_key))))
- {
- new_key->key = gui_key_get_internal_code (key);
- if (!new_key->key)
- new_key->key = strdup (key);
- if (!new_key->key)
- {
- free (new_key);
- return NULL;
- }
- new_key->command = strdup (command);
- if (!new_key->command)
- {
- free (new_key->key);
- free (new_key);
- return NULL;
- }
- gui_key_set_areas (new_key);
- gui_key_set_score (new_key);
+ new_key = malloc (sizeof (*new_key));
+ if (!new_key)
+ return NULL;
- if (buffer)
- {
- gui_key_insert_sorted (&buffer->keys, &buffer->last_key,
- &buffer->keys_count, new_key);
- }
- else
- {
- gui_key_insert_sorted (&gui_keys[context],
- &last_gui_key[context],
- &gui_keys_count[context], new_key);
- }
+ new_key->key = gui_key_get_internal_code (key);
+ if (!new_key->key)
+ new_key->key = strdup (key);
+ new_key->command = strdup (command);
+ new_key->commands = string_split_command (command, ';');
+ gui_key_set_areas (new_key);
+ gui_key_set_score (new_key);
+
+ if (buffer)
+ {
+ gui_key_insert_sorted (&buffer->keys, &buffer->last_key,
+ &buffer->keys_count, new_key);
+ }
+ else
+ {
+ gui_key_insert_sorted (&gui_keys[context],
+ &last_gui_key[context],
+ &gui_keys_count[context], new_key);
+ }
- expanded_name = gui_key_get_expanded_name (new_key->key);
+ expanded_name = gui_key_get_expanded_name (new_key->key);
- (void) hook_signal_send ("key_bind",
- WEECHAT_HOOK_SIGNAL_STRING, expanded_name);
+ (void) hook_signal_send ("key_bind",
+ WEECHAT_HOOK_SIGNAL_STRING, expanded_name);
- if (gui_key_verbose)
- {
- gui_chat_printf (NULL,
- _("New key binding (context \"%s\"): "
- "%s%s => %s%s"),
- gui_key_context_string[context],
- (expanded_name) ? expanded_name : new_key->key,
- GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
- GUI_COLOR(GUI_COLOR_CHAT),
- new_key->command);
- }
- if (expanded_name)
- free (expanded_name);
+ if (gui_key_verbose)
+ {
+ gui_chat_printf (NULL,
+ _("New key binding (context \"%s\"): "
+ "%s%s => %s%s"),
+ gui_key_context_string[context],
+ (expanded_name) ? expanded_name : new_key->key,
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ new_key->command);
}
- else
- return NULL;
+
+ if (expanded_name)
+ free (expanded_name);
return new_key;
}
@@ -1042,7 +1032,7 @@ gui_key_focus_command (const char *key, int context,
struct t_gui_key *ptr_key;
int i, errors, matching, debug, rc;
long unsigned int value;
- char *command, **commands;
+ char *command;
const char *str_buffer;
struct t_hashtable *hashtable;
struct t_weelist *list_keys;
@@ -1119,27 +1109,27 @@ gui_key_focus_command (const char *key, int context,
gui_chat_printf (NULL, _("Command for key: \"%s\""),
ptr_key->command);
}
- commands = string_split_command (ptr_key->command, ';');
- if (commands)
+ if (ptr_key->commands)
{
- for (i = 0; commands[i]; i++)
+ for (i = 0; ptr_key->commands[i]; i++)
{
- if (string_strncasecmp (commands[i], "hsignal:", 8) == 0)
+ if (string_strncasecmp (ptr_key->commands[i], "hsignal:", 8) == 0)
{
- if (commands[i][8])
+ if (ptr_key->commands[i][8])
{
if (debug)
{
gui_chat_printf (NULL,
_("Sending hsignal: \"%s\""),
- commands[i] + 8);
+ ptr_key->commands[i] + 8);
}
- (void) hook_hsignal_send (commands[i] + 8, hashtable);
+ (void) hook_hsignal_send (ptr_key->commands[i] + 8,
+ hashtable);
}
}
else
{
- command = string_replace_with_callback (commands[i],
+ command = string_replace_with_callback (ptr_key->commands[i],
"${", "}",
&gui_key_focus_command_replace_cb,
hashtable,
@@ -1162,7 +1152,6 @@ gui_key_focus_command (const char *key, int context,
}
}
}
- string_free_split_command (commands);
}
hashtable_free (hashtable);
return 1;
@@ -1259,7 +1248,7 @@ gui_key_pressed (const char *key_str)
{
int i, first_key, context, length, length_key;
struct t_gui_key *ptr_key;
- char **commands, *pos;
+ char *pos;
/* add key to buffer */
first_key = (gui_key_combo_buffer[0] == '\0');
@@ -1341,16 +1330,12 @@ gui_key_pressed (const char *key_str)
{
/* exact combo found => execute command */
gui_key_combo_buffer[0] = '\0';
- if (ptr_key->command)
+ if (ptr_key->commands)
{
- commands = string_split_command (ptr_key->command, ';');
- if (commands)
+ for (i = 0; ptr_key->commands[i]; i++)
{
- for (i = 0; commands[i]; i++)
- {
- input_data (gui_current_window->buffer, commands[i]);
- }
- string_free_split_command (commands);
+ input_data (gui_current_window->buffer,
+ ptr_key->commands[i]);
}
}
}
@@ -1396,6 +1381,8 @@ gui_key_free (struct t_gui_key **keys, struct t_gui_key **last_key,
free (key->area_key);
if (key->command)
free (key->command);
+ if (key->commands)
+ string_free_split (key->commands);
/* remove key from keys list */
if (key->prev_key)
@@ -1838,6 +1825,7 @@ gui_key_hdata_key_cb (void *data, const char *hdata_name)
HDATA_VAR(struct t_gui_key, area_name, POINTER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_key, area_key, STRING, 0, NULL, NULL);
HDATA_VAR(struct t_gui_key, command, STRING, 0, NULL, NULL);
+ HDATA_VAR(struct t_gui_key, commands, POINTER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_key, score, INTEGER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_key, prev_key, POINTER, 0, NULL, hdata_name);
HDATA_VAR(struct t_gui_key, next_key, POINTER, 0, NULL, hdata_name);
@@ -1923,7 +1911,7 @@ gui_key_add_to_infolist (struct t_infolist *infolist, struct t_gui_key *key)
void
gui_key_print_log_key (struct t_gui_key *key, const char *prefix)
{
- int area;
+ int area, i;
log_printf ("%s[key (addr:0x%lx)]", prefix, key);
log_printf ("%s key. . . . . . . . : '%s'", prefix, key->key);
@@ -1937,6 +1925,15 @@ gui_key_print_log_key (struct t_gui_key *key, const char *prefix)
}
log_printf ("%s area_key . . . . . : '%s'", prefix, key->area_key);
log_printf ("%s command. . . . . . : '%s'", prefix, key->command);
+ log_printf ("%s commands . . . . . : 0x%lx", prefix, key->commands);
+ if (key->commands)
+ {
+ for (i = 0; key->commands[i]; i++)
+ {
+ log_printf ("%s commands[%03d]. . : '%s'",
+ prefix, i, key->commands[i]);
+ }
+ }
log_printf ("%s score. . . . . . . : %d", prefix, key->score);
log_printf ("%s prev_key . . . . . : 0x%lx", prefix, key->prev_key);
log_printf ("%s next_key . . . . . : 0x%lx", prefix, key->next_key);
diff --git a/src/gui/gui-key.h b/src/gui/gui-key.h
index 81566ee86..421c7a5c5 100644
--- a/src/gui/gui-key.h
+++ b/src/gui/gui-key.h
@@ -58,7 +58,8 @@ struct t_gui_key
int area_type[2]; /* type of areas (for cursor/mouse) */
char *area_name[2]; /* name of areas (for cursor/mouse) */
char *area_key; /* key after area (after ":") */
- char *command; /* associated command (may be NULL) */
+ char *command; /* associated command */
+ char **commands; /* command split on ';' */
int score; /* score, for sorting keys */
struct t_gui_key *prev_key; /* link to previous key */
struct t_gui_key *next_key; /* link to next key */