[dovecot-cvs] dovecot/src/lib-index mail-index-view.c,1.52,1.53

tss at dovecot.org tss at dovecot.org
Tue Jan 16 14:09:25 UTC 2007


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

Modified Files:
	mail-index-view.c 
Log Message:
UID -> seq lookup: Optimize UID=1 and UID=<next_uid>-1 cases.



Index: mail-index-view.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-view.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- mail-index-view.c	28 Dec 2006 20:54:59 -0000	1.52
+++ mail-index-view.c	16 Jan 2007 14:09:23 -0000	1.53
@@ -299,6 +299,13 @@
 
 	i_assert(view->hdr.messages_count <= view->map->records_count);
 
+	if (uid == 1) {
+		/* optimization: the message can be only the first one */
+		if (view->hdr.messages_count == 0)
+			return 0;
+		*left_idx_p = 1;
+		return 1;
+	}
 	rec_base = view->map->records;
 	record_size = view->map->hdr.record_size;
 
@@ -350,23 +357,26 @@
 	if (mail_index_view_lock(view) < 0)
 		return -1;
 
-	if (last_uid >= view->map->hdr.next_uid) {
+	left_idx = 0;
+	*first_seq_r = mail_index_bsearch_uid(view, first_uid, &left_idx, 1);
+	if (*first_seq_r == 0 ||
+	    MAIL_INDEX_MAP_IDX(view->map, *first_seq_r-1)->uid > last_uid) {
+		*first_seq_r = *last_seq_r = 0;
+		return 0;
+	}
+
+	if (last_uid >= view->map->hdr.next_uid-1) {
+		/* we want the last message */
 		last_uid = view->map->hdr.next_uid-1;
 		if (first_uid > last_uid) {
-			*first_seq_r = 0;
-			*last_seq_r = 0;
+			*first_seq_r = *last_seq_r = 0;
 			return 0;
 		}
-	}
 
-	left_idx = 0;
-	*first_seq_r = mail_index_bsearch_uid(view, first_uid, &left_idx, 1);
-	if (*first_seq_r == 0 ||
-	    MAIL_INDEX_MAP_IDX(view->map, *first_seq_r-1)->uid > last_uid) {
-		*first_seq_r = 0;
-		*last_seq_r = 0;
+		*last_seq_r = view->hdr.messages_count;
 		return 0;
 	}
+
 	if (first_uid == last_uid) {
 		*last_seq_r = *first_seq_r;
 		return 0;



More information about the dovecot-cvs mailing list