summaryrefslogtreecommitdiff
path: root/libmailutils
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-12-19 22:26:28 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2010-12-19 22:26:28 +0200
commit68d83f0d247aaa3331bf8e4a29b89687c9b2e6ea (patch)
tree22531a377df79bc7380425d4970e6f4fb9b1e8c2 /libmailutils
parent094f5d94f39d5476e33dfb4e38e394746972ec74 (diff)
downloadmailutils-68d83f0d247aaa3331bf8e4a29b89687c9b2e6ea.tar.gz
mailutils-68d83f0d247aaa3331bf8e4a29b89687c9b2e6ea.tar.bz2
maildir: speed up mailbox scanning
* include/mailutils/sys/amd.h (_amd_message_lookup_or_insert): New proto. * libmailutils/base/amd.c (_amd_message_lookup_or_insert): New function. (_amd_message_insert): Rewrite using _amd_message_lookup_or_insert. * libproto/maildir/mbox.c (maildir_message_cmp): Stop comparison on ':'. (maildir_message_lookup): Remove. (maildir_scan_dir): Use _amd_message_lookup_or_insert. * po/POTFILES.in: Update.
Diffstat (limited to 'libmailutils')
-rw-r--r--libmailutils/base/amd.c35
1 files changed, 28 insertions, 7 deletions
diff --git a/libmailutils/base/amd.c b/libmailutils/base/amd.c
index b41ff21cb..f77cf3a45 100644
--- a/libmailutils/base/amd.c
+++ b/libmailutils/base/amd.c
@@ -1336,27 +1336,48 @@ amd_cleanup (void *arg)
mu_locker_unlock (mailbox->locker);
}
+int
+_amd_message_lookup_or_insert (struct _amd_data *amd,
+ struct _amd_message *key,
+ size_t *pindex)
+{
+ int result = 0;
+ size_t index;
+ if (amd_msg_lookup (amd, key, &index))
+ {
+ /* Not found. Index points to the array cell where msg would
+ be placed */
+ result = amd_array_expand (amd, index);
+ if (result)
+ return result;
+ else
+ result = MU_ERR_NOENT;
+ }
+ else
+ result = 0;
+ *pindex = index;
+ return result;
+}
+
/* Insert message msg into the message list on the appropriate position */
int
_amd_message_insert (struct _amd_data *amd, struct _amd_message *msg)
{
size_t index;
+ int rc = _amd_message_lookup_or_insert (amd, msg, &index);
- if (amd_msg_lookup (amd, msg, &index))
+ if (rc == MU_ERR_NOENT)
{
- /* Not found. Index is the index of the array cell where msg
- must be placed */
- int rc = amd_array_expand (amd, index);
- if (rc)
- return rc;
amd->msg_array[index] = msg;
msg->amd = amd;
}
- else
+ else if (rc == 0)
{
/*FIXME: Found? Shouldn't happen */
return EEXIST;
}
+ else
+ return rc;
return 0;
}

Return to:

Send suggestions and report system problems to the System administrator.