dovecot: Simplify search arguments immediately when calling mail...

dovecot at dovecot.org dovecot at dovecot.org
Sun Dec 2 23:52:55 EET 2007


details:   http://hg.dovecot.org/dovecot/rev/69babcc2fb80
changeset: 6899:69babcc2fb80
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Dec 02 23:52:50 2007 +0200
description:
Simplify search arguments immediately when calling mailbox_search_init().

diffstat:

4 files changed, 48 insertions(+), 37 deletions(-)
src/lib-storage/index/index-search.c |   37 -----------------------------
src/lib-storage/mail-search.c        |   42 ++++++++++++++++++++++++++++++++++
src/lib-storage/mail-search.h        |    4 +++
src/lib-storage/mail-storage.c       |    2 +

diffs (134 lines):

diff -r e739cffd05ef -r 69babcc2fb80 src/lib-storage/index/index-search.c
--- 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 @@ static bool search_limit_by_flags(struct
 	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 @@ static void search_get_seqset(struct ind
 	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;
diff -r e739cffd05ef -r 69babcc2fb80 src/lib-storage/mail-search.c
--- 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 @@ mail_search_args_analyze(struct mail_sea
 	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);
+}
diff -r e739cffd05ef -r 69babcc2fb80 src/lib-storage/mail-search.h
--- 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_sea
 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
diff -r e739cffd05ef -r 69babcc2fb80 src/lib-storage/mail-storage.c
--- 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 @@ mailbox_search_init(struct mailbox_trans
 		    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);
 }
 


More information about the dovecot-cvs mailing list