{
zend_ulong hash = Z_UL(5381);
+#if defined(_WIN32) || defined(__i386__) || defined(__x86_64__) || defined(__aarch64__)
+ /* Version with multiplication works better on modern CPU */
+ for (; len >= 8; len -= 8, str += 8) {
+ hash =
+ hash * 33 * 33 * 33 * 33 +
+ str[0] * 33 * 33 * 33 +
+ str[1] * 33 * 33 +
+ str[2] * 33 +
+ str[3];
+ hash =
+ hash * 33 * 33 * 33 * 33 +
+ str[4] * 33 * 33 * 33 +
+ str[5] * 33 * 33 +
+ str[6] * 33 +
+ str[7];
+ }
+ if (len >= 4) {
+ hash =
+ hash * 33 * 33 * 33 * 33 +
+ str[0] * 33 * 33 * 33 +
+ str[1] * 33 * 33 +
+ str[2] * 33 +
+ str[3];
+ len -= 4;
+ str += 4;
+ }
+ if (len >= 2) {
+ if (len > 2) {
+ hash =
+ hash * 33 * 33 * 33 +
+ str[0] * 33 * 33 +
+ str[1] * 33 +
+ str[2];
+ } else {
+ hash =
+ hash * 33 * 33 +
+ str[0] * 33 +
+ str[1];
+ }
+ } else if (len != 0) {
+ hash = hash * 33 + *str;
+ }
+#else
/* variant with the hash unrolled eight times */
for (; len >= 8; len -= 8) {
hash = ((hash << 5) + hash) + *str++;
case 0: break;
EMPTY_SWITCH_DEFAULT_CASE()
}
+#endif
/* Hash value can't be zero, so we always set the high bit */
#if SIZEOF_ZEND_LONG == 8