Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6899:69babcc2fb80 HEAD
Simplify search arguments immediately when calling mailbox_search_init().
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 02 Dec 2007 23:52:50 +0200 |
parents | e739cffd05ef |
children | 950ce0b5edb5 |
files | src/lib-storage/index/index-search.c src/lib-storage/mail-search.c src/lib-storage/mail-search.h src/lib-storage/mail-storage.c |
diffstat | 4 files changed, 48 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/index-search.c Sun Dec 02 23:51:46 2007 +0200 +++ b/src/lib-storage/index/index-search.c Sun Dec 02 23:52:50 2007 +0200 @@ -807,42 +807,6 @@ return *seq1 <= *seq2; } -static void search_args_fix_subs(struct mail_search_arg *args, bool parent_and) -{ - struct mail_search_arg *sub; - - for (; args != NULL;) { - if (args->not && (args->type == SEARCH_SUB || - args->type == SEARCH_OR)) { - /* neg(p and q and ..) == neg(p) or neg(q) or .. - neg(p or q or ..) == neg(p) and neg(q) and .. */ - args->type = args->type == SEARCH_SUB ? - SEARCH_OR : SEARCH_SUB; - args->not = FALSE; - sub = args->value.subargs; - for (; sub != NULL; sub = sub->next) - sub->not = !sub->not; - } - - if ((args->type == SEARCH_SUB && parent_and) || - (args->type == SEARCH_OR && !parent_and)) { - /* p and (q and ..) == p and q and .. - p or (q or ..) == p or q or .. */ - sub = args->value.subargs; - for (; sub->next != NULL; sub = sub->next) ; - sub->next = args->next; - *args = *args->value.subargs; - continue; - } - - if (args->type == SEARCH_SUB || args->type == SEARCH_OR) { - search_args_fix_subs(args->value.subargs, - args->type == SEARCH_SUB); - } - args = args->next; - } -} - static void search_get_seqset(struct index_search_context *ctx, struct mail_search_arg *args) { @@ -861,7 +825,6 @@ ctx->seq1 = 1; ctx->seq2 = hdr->messages_count; - search_args_fix_subs(args, TRUE); search_parse_msgset_args(hdr, args, &ctx->seq1, &ctx->seq2); if (ctx->seq1 == 0) { ctx->seq1 = 1;
--- a/src/lib-storage/mail-search.c Sun Dec 02 23:51:46 2007 +0200 +++ b/src/lib-storage/mail-search.c Sun Dec 02 23:52:50 2007 +0200 @@ -176,3 +176,45 @@ buffer_append(headers, &null, sizeof(const char *)); return buffer_get_data(headers, NULL); } + +static void +mail_search_args_simplify_sub(struct mail_search_arg *args, bool parent_and) +{ + struct mail_search_arg *sub; + + for (; args != NULL;) { + if (args->not && (args->type == SEARCH_SUB || + args->type == SEARCH_OR)) { + /* neg(p and q and ..) == neg(p) or neg(q) or .. + neg(p or q or ..) == neg(p) and neg(q) and .. */ + args->type = args->type == SEARCH_SUB ? + SEARCH_OR : SEARCH_SUB; + args->not = FALSE; + sub = args->value.subargs; + for (; sub != NULL; sub = sub->next) + sub->not = !sub->not; + } + + if ((args->type == SEARCH_SUB && parent_and) || + (args->type == SEARCH_OR && !parent_and)) { + /* p and (q and ..) == p and q and .. + p or (q or ..) == p or q or .. */ + sub = args->value.subargs; + for (; sub->next != NULL; sub = sub->next) ; + sub->next = args->next; + *args = *args->value.subargs; + continue; + } + + if (args->type == SEARCH_SUB || args->type == SEARCH_OR) { + mail_search_args_simplify_sub(args->value.subargs, + args->type == SEARCH_SUB); + } + args = args->next; + } +} + +void mail_search_args_simplify(struct mail_search_arg *args) +{ + mail_search_args_simplify_sub(args, TRUE); +}
--- a/src/lib-storage/mail-search.h Sun Dec 02 23:51:46 2007 +0200 +++ b/src/lib-storage/mail-search.h Sun Dec 02 23:52:50 2007 +0200 @@ -101,4 +101,8 @@ mail_search_args_analyze(struct mail_search_arg *args, bool *have_headers, bool *have_body); +/* 1) Change args so that SEARCH_SUB and SEARCH_OR will never have "not" set + 2) Drop unnecessary nested SEARCH_SUB and SEARCH_ORs */ +void mail_search_args_simplify(struct mail_search_arg *args); + #endif
--- a/src/lib-storage/mail-storage.c Sun Dec 02 23:51:46 2007 +0200 +++ b/src/lib-storage/mail-storage.c Sun Dec 02 23:52:50 2007 +0200 @@ -8,6 +8,7 @@ #include "mailbox-list-private.h" #include "mail-storage-private.h" #include "mail-namespace.h" +#include "mail-search.h" #include "index/index-storage.h" #include <stdlib.h> @@ -614,6 +615,7 @@ const char *charset, struct mail_search_arg *args, const enum mail_sort_type *sort_program) { + mail_search_args_simplify(args); return t->box->v.search_init(t, charset, args, sort_program); }