changeset: 6445:755a18da99bc
user:      Seth Forshee <[email protected]>
date:      Sat Apr 25 19:00:13 2015 -0700
link:      http://dev.mutt.org/hg/mutt/rev/755a18da99bc

Fix performance regression for ~b/~B searching. (closes #3743)

In mutt_is_autoview(), changeset b58cdfacfb89 introduced a call to
rfc1524_mailcap_lookup() before checking if the MIME type should
be autoviewed based on the user's preferences. This caused a major
performance regression for ~b/~B searching.

Rearrange mutt_is_autoview() to check the user preferences first, then
search for a mailcap entry only if the MIME type should be autoviewed.

In order to preserve correct mime_lookup behavior, re-add a call to
mutt_check_lookup_list() before scanning the AutoViewList.

diffs (67 lines):

diff -r 067a3ac42c3b -r 755a18da99bc handler.c
--- a/handler.c Sun Apr 19 13:15:50 2015 -0700
+++ b/handler.c Sat Apr 25 19:00:13 2015 -0700
@@ -955,36 +955,38 @@
 static int mutt_is_autoview (BODY *b)
 {
   char type[SHORT_STRING];
+  int is_autoview = 0;
 
   snprintf (type, sizeof (type), "%s/%s", TYPE (b), b->subtype);
 
+  if (option(OPTIMPLICITAUTOVIEW))
+  {
+    /* $implicit_autoview is essentially the same as "auto_view *" */
+    is_autoview = 1;
+  }
+  else
+  {
+    /* determine if this type is on the user's auto_view list */
+    LIST *t = AutoViewList;
+
+    mutt_check_lookup_list (b, type, sizeof (type));
+    for (; t; t = t->next) {
+      int i = mutt_strlen (t->data) - 1;
+      if ((i > 0 && t->data[i-1] == '/' && t->data[i] == '*' && 
+            ascii_strncasecmp (type, t->data, i) == 0) ||
+          ascii_strcasecmp (type, t->data) == 0)
+        is_autoview = 1;
+    }
+
+    if (is_mmnoask (type))
+      is_autoview = 1;
+  }
+
   /* determine if there is a mailcap entry suitable for auto_view
    *
-   * WARNING: _type is altered by this call as a result of `mime_lookup' 
support */
-  if (rfc1524_mailcap_lookup(b, type, NULL, M_AUTOVIEW))
-  {
-    if (option(OPTIMPLICITAUTOVIEW))
-    {
-      /* $implicit_autoview is essentially the same as "auto_view *" */
-      return 1;
-    }
-    else
-    {
-      /* determine if this type is on the user's auto_view list */
-      LIST *t = AutoViewList;
-
-      for (; t; t = t->next) {
-       int i = mutt_strlen (t->data) - 1;
-       if ((i > 0 && t->data[i-1] == '/' && t->data[i] == '*' && 
-             ascii_strncasecmp (type, t->data, i) == 0) ||
-           ascii_strcasecmp (type, t->data) == 0)
-         return 1;
-      }
-
-      if (is_mmnoask (type))
-       return 1;
-    }
-  }
+   * WARNING: type is altered by this call as a result of `mime_lookup' 
support */
+  if (is_autoview)
+    return rfc1524_mailcap_lookup(b, type, NULL, M_AUTOVIEW);
 
   return 0;
 }

Reply via email to