From 800928c346a98c986247107ab46db1bd88dbd82a Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Wed, 26 Sep 2001 10:56:52 +0000 Subject: [PATCH] OK, I couldn't resist. ;-) Depending on the user's usage patterns and configuration, there may be a strong bias in maildir files moving either within the new or to the cur subfolder. This patch adds hit counters for each of these directories. Mutt will then look first into the directory encountered more frequently in the past. This should help to reduce the cost of chasing messages a bit, and isn't too costly itself. (Another possibility for optimization may be to actually base the prediction on the configuration and on the message flags as we know them - in particular, the mark_old and move options could have some effect here. Thinking about message flags, one could even replace the simple heuristic currently implemented by a matrix recording hit counters depending on flags. But then again, it's all just playing around, since this function will be invoked only rarely. ;-) --- mh.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/mh.c b/mh.c index 38aa4f01..aa6a2d28 100644 --- a/mh.c +++ b/mh.c @@ -1498,12 +1498,30 @@ FILE *maildir_open_find_message (const char *folder, const char *msg) char unique[_POSIX_PATH_MAX]; FILE *fp; - maildir_canon_filename (unique, msg, sizeof (unique)); + static unsigned int new_hits = 0, cur_hits = 0; /* simple dynamic optimization */ - if ((fp = _maildir_open_find_message (folder, unique, "new")) || errno != ENOENT) + maildir_canon_filename (unique, msg, sizeof (unique)); + + if ((fp = _maildir_open_find_message (folder, unique, new_hits > cur_hits ? "new" : "cur")) || errno != ENOENT) + { + if (new_hits < UINT_MAX && cur_hits < UINT_MAX) + { + new_hits += (new_hits > cur_hits ? 1 : 0); + cur_hits += (new_hits > cur_hits ? 0 : 1); + } + return fp; - if ((fp = _maildir_open_find_message (folder, unique, "cur")) || errno != ENOENT) + } + if ((fp = _maildir_open_find_message (folder, unique, new_hits > cur_hits ? "cur" : "new")) || errno != ENOENT) + { + if (new_hits < UINT_MAX && cur_hits < UINT_MAX) + { + new_hits += (new_hits > cur_hits ? 0 : 1); + cur_hits += (new_hits > cur_hits ? 1 : 0); + } + return fp; + } return NULL; } -- 2.40.0