diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2019-10-23 19:41:43 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2019-10-23 19:45:06 +0200 |
commit | ecc7edda9e1acc43fcf6effc72120e54bda4a655 (patch) | |
tree | 3b7fa180e6ac3c03f468eb067d762b4dd5b5e842 /src/core | |
parent | fbc9faed42bec4b262e1e7b16622deebea08b98c (diff) | |
download | weechat-ecc7edda9e1acc43fcf6effc72120e54bda4a655.zip |
core: optimize search of options in configuration sections
Since options are sorted in sections, it is faster to search from the last
option to the first one.
For configuration files with many options in a single section (like
plugins.conf), the load of configuration file is about 2 to 3x faster.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/wee-config-file.c | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index 5b014c27d..5787c3cc8 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -416,12 +416,13 @@ config_file_option_find_pos (struct t_config_section *section, const char *name) if (section && name) { - for (ptr_option = section->options; ptr_option; - ptr_option = ptr_option->next_option) + for (ptr_option = section->last_option; ptr_option; + ptr_option = ptr_option->prev_option) { - if (string_strcasecmp (name, ptr_option->name) < 0) - return ptr_option; + if (string_strcasecmp (name, ptr_option->name) >= 0) + return ptr_option->next_option; } + return section->options; } /* position not found (we will add to the end of list) */ @@ -832,14 +833,18 @@ config_file_search_option (struct t_config_file *config_file, { struct t_config_section *ptr_section; struct t_config_option *ptr_option; + int rc; if (section) { - for (ptr_option = section->options; ptr_option; - ptr_option = ptr_option->next_option) + for (ptr_option = section->last_option; ptr_option; + ptr_option = ptr_option->prev_option) { - if (string_strcasecmp (ptr_option->name, option_name) == 0) + rc = string_strcasecmp (ptr_option->name, option_name); + if (rc == 0) return ptr_option; + else if (rc < 0) + return NULL; } } else if (config_file) @@ -847,11 +852,14 @@ config_file_search_option (struct t_config_file *config_file, for (ptr_section = config_file->sections; ptr_section; ptr_section = ptr_section->next_section) { - for (ptr_option = ptr_section->options; ptr_option; - ptr_option = ptr_option->next_option) + for (ptr_option = ptr_section->last_option; ptr_option; + ptr_option = ptr_option->prev_option) { - if (string_strcasecmp (ptr_option->name, option_name) == 0) + rc = string_strcasecmp (ptr_option->name, option_name); + if (rc == 0) return ptr_option; + else if (rc < 0) + return NULL; } } } @@ -876,21 +884,25 @@ config_file_search_section_option (struct t_config_file *config_file, { struct t_config_section *ptr_section; struct t_config_option *ptr_option; + int rc; *section_found = NULL; *option_found = NULL; if (section) { - for (ptr_option = section->options; ptr_option; - ptr_option = ptr_option->next_option) + for (ptr_option = section->last_option; ptr_option; + ptr_option = ptr_option->prev_option) { - if (string_strcasecmp (ptr_option->name, option_name) == 0) + rc = string_strcasecmp (ptr_option->name, option_name); + if (rc == 0) { *section_found = section; *option_found = ptr_option; return; } + else if (rc < 0) + return; } } else if (config_file) @@ -898,14 +910,18 @@ config_file_search_section_option (struct t_config_file *config_file, for (ptr_section = config_file->sections; ptr_section; ptr_section = ptr_section->next_section) { - for (ptr_option = ptr_section->options; ptr_option; - ptr_option = ptr_option->next_option) + for (ptr_option = ptr_section->last_option; ptr_option; + ptr_option = ptr_option->prev_option) { - if (string_strcasecmp (ptr_option->name, option_name) == 0) + rc = string_strcasecmp (ptr_option->name, option_name); + if (rc == 0) { *section_found = ptr_section; *option_found = ptr_option; + return; } + else if (rc < 0) + return; } } } |