@@ -20,15 +20,33 @@
#define _DL_NEW_HASH_H 1
#include <stdint.h>
+/* For __glibc_unlikely. */
+#include <sys/cdefs.h>
static inline uint32_t
__attribute__ ((unused))
_dl_new_hash (const char *s)
{
- uint32_t h = 5381;
- for (unsigned char c = *s; c != '\0'; c = *++s)
- h = h * 33 + c;
- return h;
+ unsigned int h = 5381;
+ unsigned char c0, c1;
+ for (;;)
+ {
+ c0 = *s;
+ /* Unlikely length zero string so evens will be slightly less
+ common. */
+ if (__glibc_unlikely (c0 == 0))
+ {
+ return h;
+ }
+
+ c1 = *(s + 1);
+ if (c1 == 0)
+ {
+ return h * 33 + c0;
+ }
+ h = 33 * 33 * h + 33 * c0 + c1;
+ s += 2;
+ }
}