From: Timo Sirainen Date: Mon, 7 Apr 2025 10:14:38 +0000 (+0300) Subject: config: Reimplement config_parsed_key_lookup() with all_keys hash table X-Git-Tag: 2.4.2~812 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2aca8c845ed2a9ee40e9c960540ad2c888f46548;p=thirdparty%2Fdovecot%2Fcore.git config: Reimplement config_parsed_key_lookup() with all_keys hash table --- diff --git a/src/config/config-parser.c b/src/config/config-parser.c index eb75f39dda..42eb82bbb1 100644 --- a/src/config/config-parser.c +++ b/src/config/config-parser.c @@ -49,7 +49,6 @@ struct config_parsed { struct config_module_parser *module_parsers; ARRAY_TYPE(config_path) seen_paths; ARRAY_TYPE(const_string) errors; - HASH_TABLE(const char *, const struct setting_define *) key_hash; HASH_TABLE_TYPE(include_group) include_groups; HASH_TABLE_TYPE(config_key) all_keys; }; @@ -3202,10 +3201,10 @@ config_parsed_get_filter_parsers(struct config_parsed *config) return config->filter_parsers; } -const HASH_TABLE_TYPE(config_key) * +HASH_TABLE_TYPE(config_key) config_parsed_get_all_keys(struct config_parsed *config) { - return &config->all_keys; + return config->all_keys; } static void @@ -3320,21 +3319,11 @@ config_parsed_get_setting_change_counter(struct config_parsed *config, const struct setting_define * config_parsed_key_lookup(struct config_parsed *config, const char *key) { - const struct config_module_parser *l; - unsigned int key_idx; - - if (hash_table_is_created(config->key_hash)) - return hash_table_lookup(config->key_hash, key); - hash_table_create(&config->key_hash, config->pool, 0, str_hash, strcmp); - - for (l = config->module_parsers; l->info != NULL; l++) { - for (key_idx = 0; l->info->defines[key_idx].key != NULL; key_idx++) { - hash_table_update(config->key_hash, - l->info->defines[key_idx].key, - &l->info->defines[key_idx]); - } - } - return hash_table_lookup(config->key_hash, key); + struct config_parser_key *config_key = + hash_table_lookup(config->all_keys, key); + if (config_key == NULL) + return NULL; + return &all_infos[config_key->info_idx]->defines[config_key->define_idx]; } static bool config_filter_tree_has_settings(struct config_filter_parser *filter, @@ -3407,7 +3396,6 @@ void config_parsed_free(struct config_parsed **_config) hash_table_destroy(&config->include_groups); hash_table_destroy(&config->all_keys); - hash_table_destroy(&config->key_hash); pool_unref(&config->pool); } diff --git a/src/config/config-parser.h b/src/config/config-parser.h index d48c2b4a53..f7c5d08a28 100644 --- a/src/config/config-parser.h +++ b/src/config/config-parser.h @@ -114,7 +114,7 @@ config_parsed_get_filter_parsers(struct config_parsed *config); void config_fill_set_parser(struct setting_parser_context *parser, const struct config_module_parser *p, bool expand_values); -const HASH_TABLE_TYPE(config_key) * +HASH_TABLE_TYPE(config_key) config_parsed_get_all_keys(struct config_parsed *config); /* Returns the value for a specified setting. The setting must be found and it must be a string, or the function panics. */