From 57b5fe6156124cdbe294f06d7e9ab99bd076854b Mon Sep 17 00:00:00 2001 From: djcb Date: Sun, 29 Oct 2017 13:34:57 +0200 Subject: [PATCH] mu: some optimizations add fast-path for (common) plain-ascii. fix silly static misuse. should improve indexing with some single-digit percentage. --- lib/mu-msg-fields.c | 4 +--- lib/parser/utils.cc | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/mu-msg-fields.c b/lib/mu-msg-fields.c index 374719ad..3cdbd477 100644 --- a/lib/mu-msg-fields.c +++ b/lib/mu-msg-fields.c @@ -256,9 +256,7 @@ static const MuMsgField FIELD_DATA[] = { static MuMsgField* _msg_field_data[MU_MSG_FIELD_ID_NUM]; static const MuMsgField* mu_msg_field (MuMsgFieldId id) { - static gboolean _initialized; - - _initialized = FALSE; + static gboolean _initialized = FALSE; /* initialize the array, but only once... */ if (G_UNLIKELY(!_initialized)) { diff --git a/lib/parser/utils.cc b/lib/parser/utils.cc index 789ba1a5..825ca725 100644 --- a/lib/parser/utils.cc +++ b/lib/parser/utils.cc @@ -99,11 +99,27 @@ gx_utf8_flatten (const gchar *str, gssize len) std::string // gx_utf8_flatten Mux::utf8_flatten (const std::string& str) { + // optimization for boring old ascii strings + bool is_ascii = true; + std::string s{str}; + for (auto it = s.begin(); it != s.end(); ++it) { + if (*it & 0x80) { + is_ascii = false; + break; + } else + *it = tolower(*it); + } + + if (G_LIKELY(is_ascii)) + return s; + /////////////////////////////////////////// + + // seems we need the big guns char *flat = gx_utf8_flatten (str.c_str(), str.length()); if (!flat) return {}; - std::string s(flat); + s = flat; g_free (flat); return s;