]> granicus.if.org Git - mutt/commitdiff
OK, I couldn't resist. ;-)
authorThomas Roessler <roessler@does-not-exist.org>
Wed, 26 Sep 2001 10:56:52 +0000 (10:56 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Wed, 26 Sep 2001 10:56:52 +0000 (10:56 +0000)
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

diff --git a/mh.c b/mh.c
index 38aa4f01642ca4800d74eec18e8bbde9f9ce3a0c..aa6a2d286a18f281161c35d76a8c21917fe21444 100644 (file)
--- 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;  
 }