From: <no-...@en...> - 2008-09-15 13:38:45
|
Author: cedric Date: 2008-09-15 06:38:42 -0700 (Mon, 15 Sep 2008) New Revision: 36001 Modified: trunk/PROTO/eina/src/include/eina_inline_hash.x trunk/PROTO/eina/src/lib/eina_stringshare.c Log: Don't compute string length when not really needed. Modified: trunk/PROTO/eina/src/include/eina_inline_hash.x =================================================================== --- trunk/PROTO/eina/src/include/eina_inline_hash.x 2008-09-15 12:54:54 UTC (rev 36000) +++ trunk/PROTO/eina/src/include/eina_inline_hash.x 2008-09-15 13:38:42 UTC (rev 36001) @@ -30,11 +30,27 @@ const unsigned char *ptr; if (!key) return 0; - for (ptr = (unsigned char *)key; len; ptr++, len--) hash_num = ((hash_num << 5) + hash_num) ^ *ptr; /* hash * 33 ^ c */ return (int)hash_num; } +static inline int +eina_hash_djb2_len(const char *key, int *plen) +{ + unsigned int hash_num = 5381; + int len = 0; + const unsigned char *ptr; + + if (!key) return 0; + + for (ptr = (unsigned char *)key; *ptr; ptr++, len++) + hash_num = ((hash_num << 5) + hash_num) ^ *ptr; /* hash * 33 ^ c */ + + *plen = len + 1; + + return (int)hash_num; +} + #endif Modified: trunk/PROTO/eina/src/lib/eina_stringshare.c =================================================================== --- trunk/PROTO/eina/src/lib/eina_stringshare.c 2008-09-15 12:54:54 UTC (rev 36000) +++ trunk/PROTO/eina/src/lib/eina_stringshare.c 2008-09-15 13:38:42 UTC (rev 36001) @@ -179,8 +179,7 @@ int hash_num, slen, hash; if (!str) return NULL; - slen = strlen(str) + 1; - hash = eina_hash_djb2(str, slen); + hash = eina_hash_djb2_len(str, &slen); hash_num = hash & 0xFF; hash &= 0xFFF; @@ -240,8 +239,7 @@ int hash_num, slen, hash; if (!str) return; - slen = strlen(str) + 1; - hash = eina_hash_djb2(str, slen); + hash = eina_hash_djb2_len(str, &slen); hash_num = hash & 0xFF; hash &= 0xFFF; |