talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit b20a6fa6d4a20ecc94bb6ad417a2b7ab08f98ed1
parent 618839aae3e97e0869fcc2c9b2b25f86995877b0
Author: Colin Leroy <colin@colino.net>
Date:   Sat,  6 Oct 2018 11:26:53 +0200

Halve the time spent manipulating case in case-insensitive searches

Diffstat:
Msrc/matcher.c | 12+++++++++---
Msrc/matcher.h | 5++++-
2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/matcher.c b/src/matcher.c @@ -324,6 +324,7 @@ MatcherProp *matcherprop_new(gint criteria, const gchar *header, #ifndef G_OS_WIN32 prop->preg = NULL; #endif + prop->casefold_expr = NULL; prop->value = value; prop->error = 0; @@ -345,6 +346,7 @@ void matcherprop_free(MatcherProp *prop) regfree(prop->preg); g_free(prop->preg); } + g_free(prop->casefold_expr); #endif g_free(prop); } @@ -368,6 +370,7 @@ MatcherProp *matcherprop_copy(const MatcherProp *src) #ifndef G_OS_WIN32 prop->preg = NULL; /* will be re-evaluated */ #endif + prop->casefold_expr = src->casefold_expr ? g_strdup(src->casefold_expr) : NULL; prop->value = src->value; prop->error = src->error; return prop; @@ -475,7 +478,7 @@ static gboolean matcherprop_string_match(MatcherProp *prop, const gchar *str, const gchar *debug_context) { gchar *str1; - gchar *down_expr; + const gchar *down_expr; gboolean ret = FALSE; gboolean should_free = FALSE; if (str == NULL) @@ -484,7 +487,11 @@ static gboolean matcherprop_string_match(MatcherProp *prop, const gchar *str, if (prop->matchtype == MATCHTYPE_REGEXPCASE || prop->matchtype == MATCHTYPE_MATCHCASE) { str1 = g_utf8_casefold(str, -1); - down_expr = g_utf8_casefold(prop->expr, -1); + if (!prop->casefold_expr) { + prop->casefold_expr = g_utf8_casefold(prop->expr, -1); + } + down_expr = prop->casefold_expr; + should_free = TRUE; } else { str1 = (gchar *)str; @@ -569,7 +576,6 @@ static gboolean matcherprop_string_match(MatcherProp *prop, const gchar *str, free_strs: if (should_free) { g_free(str1); - g_free(down_expr); } return ret; } diff --git a/src/matcher.h b/src/matcher.h @@ -36,10 +36,13 @@ struct _MatcherProp { gchar *header; gchar *expr; int value; - regex_t *preg; int error; gboolean result; gboolean done; + /* Allows recompiling expr each time */ + regex_t *preg; + /* Allows casefolding expr each time */ + gchar *casefold_expr; }; struct _MatcherList {