diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-01-02 12:21:43 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-01-02 20:28:27 +0900 |
| commit | 4ac73307fdf7996484378fdd6e09c02e5e7efbdc (patch) | |
| tree | 14b5f5038ecf09593cfe00176b5cc0306d4350aa /src/string.c | |
| parent | 6323c995f37fe24597c431fe5515394716dedb0d (diff) | |
| download | mruby-4ac73307fdf7996484378fdd6e09c02e5e7efbdc.tar.gz mruby-4ac73307fdf7996484378fdd6e09c02e5e7efbdc.zip | |
Reduce strength of the hash function; ref #5201
Also avoid using `uint64_t`.
Diffstat (limited to 'src/string.c')
| -rw-r--r-- | src/string.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/string.c b/src/string.c index 0cb9eaf83..4e8bd7835 100644 --- a/src/string.c +++ b/src/string.c @@ -1752,13 +1752,13 @@ 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); - uint64_t key = 0; + uint32_t key = 0; while (len--) { - key = key*65599 + *p; + key = (key << 6) + (key << 16) - key + *p; p++; } - return (uint32_t)(key + (key>>5)); + return key + (key>>5); } /* 15.2.10.5.20 */ |
