diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2023-03-19 08:30:32 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-03-19 08:30:32 +0100 |
commit | 3e5d77fdff1f42cd593b5dbd5b585b9cd2830a86 (patch) | |
tree | 52f9a74d71bba58f19e602bf3a47ba74ea68ba8a /src/core/wee-command.c | |
parent | 0d49ffd0536997858596d9c70a235c18c3295632 (diff) | |
download | weechat-3e5d77fdff1f42cd593b5dbd5b585b9cd2830a86.zip |
core: optimize commands `/reset` and `/unset` with a mask
Diffstat (limited to 'src/core/wee-command.c')
-rw-r--r-- | src/core/wee-command.c | 56 |
1 files changed, 21 insertions, 35 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index ee8ec833c..48fe26d00 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -5737,8 +5737,8 @@ COMMAND_CALLBACK(reset) struct t_config_section *ptr_section; struct t_config_option *ptr_option, *next_option; const char *ptr_name; - char *option_full_name; - int mask, length, number_reset; + char option_full_name[4096]; + int mask, number_reset; /* make C compiler happy */ (void) pointer; @@ -5780,22 +5780,15 @@ COMMAND_CALLBACK(reset) { next_option = ptr_option->next_option; - length = strlen (ptr_config->name) + 1 - + strlen (ptr_section->name) + 1 - + strlen (ptr_option->name) + 1; - option_full_name = malloc (length); - if (option_full_name) + snprintf (option_full_name, sizeof (option_full_name), + "%s.%s.%s", + ptr_config->name, ptr_section->name, + ptr_option->name); + if (string_match (option_full_name, ptr_name, 1)) { - snprintf (option_full_name, length, "%s.%s.%s", - ptr_config->name, ptr_section->name, - ptr_option->name); - if (string_match (option_full_name, ptr_name, 1)) - { - command_reset_option (ptr_option, - option_full_name, - &number_reset); - } - free (option_full_name); + command_reset_option (ptr_option, + option_full_name, + &number_reset); } ptr_option = next_option; @@ -6648,8 +6641,8 @@ COMMAND_CALLBACK(unset) struct t_config_section *ptr_section; struct t_config_option *ptr_option, *next_option; const char *ptr_name; - char *option_full_name; - int mask, length, number_reset, number_removed; + char option_full_name[4096]; + int mask, number_reset, number_removed; /* make C compiler happy */ (void) pointer; @@ -6692,23 +6685,16 @@ COMMAND_CALLBACK(unset) { next_option = ptr_option->next_option; - length = strlen (ptr_config->name) + 1 - + strlen (ptr_section->name) + 1 - + strlen (ptr_option->name) + 1; - option_full_name = malloc (length); - if (option_full_name) + snprintf (option_full_name, sizeof (option_full_name), + "%s.%s.%s", + ptr_config->name, ptr_section->name, + ptr_option->name); + if (string_match (option_full_name, ptr_name, 1)) { - snprintf (option_full_name, length, "%s.%s.%s", - ptr_config->name, ptr_section->name, - ptr_option->name); - if (string_match (option_full_name, ptr_name, 1)) - { - command_unset_option (ptr_option, - option_full_name, - &number_reset, - &number_removed); - } - free (option_full_name); + command_unset_option (ptr_option, + option_full_name, + &number_reset, + &number_removed); } ptr_option = next_option; |