[dovecot-cvs] dovecot/src/lib-storage mail-sort.c,1.1,1.2 mail-sort.h,1.1,1.2

cras at procontrol.fi cras at procontrol.fi
Fri Dec 6 00:37:35 EET 2002


Update of /home/cvs/dovecot/src/lib-storage
In directory danu:/tmp/cvs-serv15847

Modified Files:
	mail-sort.c mail-sort.h 
Log Message:
Small cleanups.



Index: mail-sort.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/mail-sort.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- mail-sort.c	4 Dec 2002 18:28:37 -0000	1.1
+++ mail-sort.c	5 Dec 2002 22:37:33 -0000	1.2
@@ -8,7 +8,7 @@
 
 struct _MailSortContext {
 	MailSortType output[MAX_SORT_PROGRAM_SIZE];
-	MailSortType output_mask, common_mask;
+	MailSortType common_mask;
 
 	MailSortFuncs funcs;
 	void *func_context;
@@ -56,14 +56,15 @@
 }
 
 static MailSortType
-mail_sort_get_common_mask(const MailSortType *input, const MailSortType *output)
+mail_sort_get_common_mask(const MailSortType *input,
+			  const MailSortType **output)
 {
 	MailSortType mask = 0;
 
-	while (*input == *output && *input != MAIL_SORT_END) {
+	while (*input == **output && *input != MAIL_SORT_END) {
 		if (*input != MAIL_SORT_REVERSE)
 			mask |= *input;
-		input++; output++;
+		input++; (*output)++;
 	}
 
 	return mask;
@@ -74,12 +75,22 @@
 {
 	MailSortContext *ctx;
 	MailSortType norm_input[MAX_SORT_PROGRAM_SIZE];
+	MailSortType norm_output[MAX_SORT_PROGRAM_SIZE];
+	int i;
 
 	ctx = i_new(MailSortContext, 1);
 
 	mail_sort_normalize(input, norm_input);
-	ctx->output_mask = mail_sort_normalize(output, ctx->output);
-        ctx->common_mask = mail_sort_get_common_mask(norm_input, ctx->output);
+	mail_sort_normalize(output, norm_output);
+
+	/* remove the common part from output, we already know input is sorted
+	   that much so we don't have to worry about it. */
+	output = norm_output;
+        ctx->common_mask = mail_sort_get_common_mask(norm_input, &output);
+
+	for (i = 0; output[i] != MAIL_SORT_END; i++)
+		ctx->output[i] = output[i];
+	ctx->output[i] = MAIL_SORT_END;
 
 	ctx->sort_buffer_alloc = 128;
 	ctx->sort_buffer = i_new(unsigned int, ctx->sort_buffer_alloc);

Index: mail-sort.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/mail-sort.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- mail-sort.h	4 Dec 2002 18:28:37 -0000	1.1
+++ mail-sort.h	5 Dec 2002 22:37:33 -0000	1.2
@@ -42,8 +42,8 @@
 				MailSortFuncs funcs, void *context);
 void mail_sort_deinit(MailSortContext *ctx);
 
-/* id is either UID or sequence number of message, depending which one we
-   want to send user. */
+/* id is either UID or sequence number of message, whichever is preferred
+   in MailSortFuncs parameters. */
 void mail_sort_input(MailSortContext *ctx, unsigned int id);
 
 #endif




More information about the dovecot-cvs mailing list