31 lines
1.3 KiB
Diff
31 lines
1.3 KiB
Diff
# UNDF: UNDF-2026-000000053
|
||
--- a/src/lib-storage/mail-storage-hooks.c
|
||
+++ b/src/lib-storage/mail-storage-hooks.c
|
||
@@ -119,12 +119,21 @@ static void mail_user_add_plugin_hooks(struct mail_user *user)
|
||
const struct mail_storage_module_hooks *module_hook;
|
||
ARRAY(struct mail_storage_module_hooks) tmp_hooks;
|
||
const char *name;
|
||
+ ARRAY_TYPE(const_string) sorted_plugins;
|
||
+
|
||
+ /* Build a sorted copy of mail_plugins for O(log P) binary search.
|
||
+ Avoids O(H×P) from array_lsearch inside the array_foreach loop
|
||
+ (H = module_hooks count, P = mail_plugins count). */
|
||
+ if (array_is_created(&user->set->mail_plugins)) {
|
||
+ t_array_init(&sorted_plugins, array_count(&user->set->mail_plugins));
|
||
+ array_append_array(&sorted_plugins, &user->set->mail_plugins);
|
||
+ array_sort(&sorted_plugins, i_strcmp_p);
|
||
+ }
|
||
|
||
/* first get all hooks wanted by the user */
|
||
t_array_init(&tmp_hooks, array_count(&module_hooks));
|
||
array_foreach(&module_hooks, module_hook) {
|
||
if (!module_hook->forced) {
|
||
name = module_get_plugin_name(module_hook->module);
|
||
if (!array_is_created(&user->set->mail_plugins) ||
|
||
- array_lsearch(&user->set->mail_plugins, &name,
|
||
- i_strcmp_p) == NULL)
|
||
+ array_bsearch(&sorted_plugins, &name,
|
||
+ i_strcmp_p) == NULL)
|
||
continue;
|
||
}
|
||
array_push_back(&tmp_hooks, module_hook);
|