mu: optimize indexing (get_uid_term)

Some users were report seeing get_uid_term high in the profiles; so
optimize this:

- make mu_util_get_hash a static inline function (used by get_uid_term)
- don't use 'realpath' in get_uid_term, seem that's the main culprit
- some slight faster string handling there too.
This commit is contained in:
djcb
2015-11-17 10:55:56 +02:00
parent dba2e50979
commit fe8b3430c6
4 changed files with 26 additions and 39 deletions

View File

@ -513,9 +513,26 @@ gboolean mu_util_g_set_error (GError **err, MuError errcode, const char *frm, ..
* @return the hash as a static string, which stays valid until this
* function is called again.
*/
const char* mu_util_get_hash (const char* str);
static inline const char*
mu_util_get_hash (const char* str)
{
unsigned djbhash, bkdrhash, bkdrseed;
unsigned u;
static char hex[18];
djbhash = 5381;
bkdrhash = 0;
bkdrseed = 1313;
for(u = 0; str[u]; ++u) {
djbhash = ((djbhash << 5) + djbhash) + str[u];
bkdrhash = bkdrhash * bkdrseed + str[u];
}
snprintf (hex, sizeof(hex), "%08x%08x", djbhash, bkdrhash);
return hex;
}
#define MU_COLOR_RED "\x1b[31m"