From 314cb05090e3bd13a132ebdbfdcdae3aa87cc86c Mon Sep 17 00:00:00 2001 From: Seth Forshee Date: Sat, 25 Apr 2015 19:00:13 -0700 Subject: [PATCH] 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. --- handler.c | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/handler.c b/handler.c index 9313c1d5..0d71296c 100644 --- a/handler.c +++ b/handler.c @@ -955,37 +955,39 @@ static int is_mmnoask (const char *buf) 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); - /* 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)) { - if (option(OPTIMPLICITAUTOVIEW)) - { - /* $implicit_autoview is essentially the same as "auto_view *" */ - return 1; + /* $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; } - 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; - } + 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 (is_autoview) + return rfc1524_mailcap_lookup(b, type, NULL, M_AUTOVIEW); + return 0; } -- 2.40.0