mirror of https://github.com/djcb/mu.git
mu: some optimizations
add fast-path for (common) plain-ascii. fix silly static misuse. should improve indexing with some single-digit percentage.
This commit is contained in:
parent
3bc53af575
commit
57b5fe6156
|
@ -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)) {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue