[dovecot-cvs] dovecot/src/lib-storage/index index-storage.h, 1.95, 1.96 index-sync.c, 1.48, 1.49

cras at dovecot.org cras at dovecot.org
Fri Jan 6 16:50:37 EET 2006


Update of /var/lib/cvs/dovecot/src/lib-storage/index
In directory talvi:/tmp/cvs-serv2323/lib-storage/index

Modified Files:
	index-storage.h index-sync.c 
Log Message:
We assumed that keyword index arrays were always sorted. This isn't always
the case. Caused unneeded keyword updates.



Index: index-storage.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-storage.h,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -d -r1.95 -r1.96
--- index-storage.h	14 Aug 2005 21:54:24 -0000	1.95
+++ index-storage.h	6 Jan 2006 14:50:35 -0000	1.96
@@ -179,4 +179,6 @@
 int index_transaction_commit(struct mailbox_transaction_context *t);
 void index_transaction_rollback(struct mailbox_transaction_context *t);
 
+int index_keyword_array_cmp(const array_t *k1, const array_t *k2);
+
 #endif

Index: index-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-sync.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- index-sync.c	8 Apr 2005 12:14:43 -0000	1.48
+++ index-sync.c	6 Jan 2006 14:50:35 -0000	1.49
@@ -267,3 +267,32 @@
 	i_free(ctx);
 	return ret;
 }
+
+int index_keyword_array_cmp(const array_t *k1, const array_t *k2)
+{
+	ARRAY_SET_TYPE(k1, unsigned int);
+	ARRAY_SET_TYPE(k2, unsigned int);
+	const unsigned int *idx1, *idx2;
+	unsigned int i, j, count1, count2;
+
+	/* The arrays may not be sorted, but they usually are. Optimize for
+	   the assumption that they are */
+	idx1 = array_get(k1, &count1);
+	idx2 = array_get(k2, &count2);
+
+	if (count1 != count2)
+		return FALSE;
+
+	for (i = 0; i < count1; i++) {
+		if (idx1[i] != idx2[i]) {
+			/* not found / unsorted array. check. */
+			for (j = 0; j < count1; j++) {
+				if (idx1[i] == idx2[j])
+					break;
+			}
+			if (j == count1)
+				return FALSE;
+		}
+	}
+	return TRUE;
+}



More information about the dovecot-cvs mailing list