# HG changeset patch # User Timo Sirainen # Date 1449573204 -7200 # Node ID f894dbea72262f99ff640ce2e7e672700bf72524 # Parent 93bff1584e5e9237ff098063ff5faa4ef3906469 lib-storage: mail_search_args_simplify() code cleanup - allow merging first arg diff -r 93bff1584e5e -r f894dbea7226 src/lib-storage/mail-search-args-simplify.c --- a/src/lib-storage/mail-search-args-simplify.c Tue Dec 08 13:13:10 2015 +0200 +++ b/src/lib-storage/mail-search-args-simplify.c Tue Dec 08 13:13:24 2015 +0200 @@ -461,10 +461,10 @@ static bool mail_search_args_simplify_sub(struct mailbox *box, pool_t pool, - struct mail_search_arg *args, bool parent_and) + struct mail_search_arg **argsp, bool parent_and) { struct mail_search_simplify_ctx ctx; - struct mail_search_arg *sub, *prev_arg = NULL; + struct mail_search_arg *sub; bool merged; memset(&ctx, 0, sizeof(ctx)); @@ -474,7 +474,9 @@ mail_search_simplify_prev_arg_hash, mail_search_simplify_prev_arg_cmp); - while (args != NULL) { + while (*argsp != NULL) { + struct mail_search_arg *args = *argsp; + if (args->match_not && (args->type == SEARCH_SUB || args->type == SEARCH_OR)) { /* neg(p and q and ..) == neg(p) or neg(q) or .. @@ -517,7 +519,7 @@ if (mail_search_args_simplify_extract_common(&args->value.subargs, pool, and_arg)) ctx.removals = TRUE; } - if (mail_search_args_simplify_sub(box, pool, args->value.subargs, + if (mail_search_args_simplify_sub(box, pool, &args->value.subargs, args->type != SEARCH_OR)) ctx.removals = TRUE; } @@ -559,15 +561,12 @@ break; } if (merged) { - i_assert(prev_arg != NULL); - prev_arg->next = args->next; - args = args->next; + *argsp = args->next; ctx.removals = TRUE; continue; } - prev_arg = args; - args = args->next; + argsp = &args->next; } hash_table_destroy(&ctx.prev_args); pool_unref(&ctx.pool); @@ -646,11 +645,11 @@ args->simplified = TRUE; - removals = mail_search_args_simplify_sub(args->box, args->pool, args->args, TRUE); + removals = mail_search_args_simplify_sub(args->box, args->pool, &args->args, TRUE); if (mail_search_args_unnest_inthreads(args, &args->args, FALSE, TRUE)) { /* we may have added some extra SUBs that could be dropped */ - if (mail_search_args_simplify_sub(args->box, args->pool, args->args, TRUE)) + if (mail_search_args_simplify_sub(args->box, args->pool, &args->args, TRUE)) removals = TRUE; } for (;;) { @@ -660,6 +659,6 @@ removals = TRUE; if (!removals) break; - removals = mail_search_args_simplify_sub(args->box, args->pool, args->args, TRUE); + removals = mail_search_args_simplify_sub(args->box, args->pool, &args->args, TRUE); } }