summaryrefslogtreecommitdiffhomepage
path: root/src/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/string.c')
-rw-r--r--src/string.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/string.c b/src/string.c
index 749d32698..946dc8be1 100644
--- a/src/string.c
+++ b/src/string.c
@@ -1752,13 +1752,17 @@ mrb_str_hash(mrb_state *mrb, mrb_value str)
struct RString *s = mrb_str_ptr(str);
mrb_int len = RSTR_LEN(s);
char *p = RSTR_PTR(s);
- uint32_t key = 0;
+ uint32_t hash = 0;
- while (len--) {
- key = (key << 6) + (key << 16) - key + *p;
- p++;
+ for(int i = 0; i < len; ++i) {
+ hash += p[i];
+ hash += (hash << 10);
+ hash ^= (hash >> 6);
}
- return key + (key>>5);
+ hash += (hash << 3);
+ hash ^= (hash >> 11);
+ hash += (hash << 15);
+ return hash;
}
/* 15.2.10.5.20 */