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:
@ -256,9 +256,7 @@ static const MuMsgField FIELD_DATA[] = {
|
|||||||
static MuMsgField* _msg_field_data[MU_MSG_FIELD_ID_NUM];
|
static MuMsgField* _msg_field_data[MU_MSG_FIELD_ID_NUM];
|
||||||
static const MuMsgField* mu_msg_field (MuMsgFieldId id)
|
static const MuMsgField* mu_msg_field (MuMsgFieldId id)
|
||||||
{
|
{
|
||||||
static gboolean _initialized;
|
static gboolean _initialized = FALSE;
|
||||||
|
|
||||||
_initialized = FALSE;
|
|
||||||
|
|
||||||
/* initialize the array, but only once... */
|
/* initialize the array, but only once... */
|
||||||
if (G_UNLIKELY(!_initialized)) {
|
if (G_UNLIKELY(!_initialized)) {
|
||||||
|
|||||||
@ -99,11 +99,27 @@ gx_utf8_flatten (const gchar *str, gssize len)
|
|||||||
std::string // gx_utf8_flatten
|
std::string // gx_utf8_flatten
|
||||||
Mux::utf8_flatten (const std::string& str)
|
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());
|
char *flat = gx_utf8_flatten (str.c_str(), str.length());
|
||||||
if (!flat)
|
if (!flat)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
std::string s(flat);
|
s = flat;
|
||||||
g_free (flat);
|
g_free (flat);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
|
|||||||
Reference in New Issue
Block a user