[dovecot-cvs] dovecot/src/lib-index mail-index-view.c, 1.44.2.3, 1.44.2.4
tss at dovecot.org
tss at dovecot.org
Tue Jan 16 14:09:22 UTC 2007
Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv20158
Modified Files:
Tag: branch_1_0
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.44.2.3
retrieving revision 1.44.2.4
diff -u -d -r1.44.2.3 -r1.44.2.4
--- mail-index-view.c 28 Dec 2006 20:54:56 -0000 1.44.2.3
+++ mail-index-view.c 16 Jan 2007 14:09:20 -0000 1.44.2.4
@@ -296,6 +296,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;
@@ -347,23 +354,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