summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-12-17 00:30:00 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-12-17 00:30:00 +0900
commitab7f54688b495b3218843e58992b713c3b28011f (patch)
treee5b9e1980d3ea913430ec79c0ada2c9001a5fe01 /string.c
parent2f595c744e10f7d5222c477efd50fe168fe9d47e (diff)
Stir the hash value more with encoding index
Diffstat (limited to 'string.c')
-rw-r--r--string.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/string.c b/string.c
index c38473481f..e46af72def 100644
--- a/string.c
+++ b/string.c
@@ -3586,11 +3586,12 @@ rb_str_prepend_multi(int argc, VALUE *argv, VALUE str)
st_index_t
rb_str_hash(VALUE str)
{
+ st_index_t h = rb_memhash((const void *)RSTRING_PTR(str), RSTRING_LEN(str));
int e = RSTRING_LEN(str) ? ENCODING_GET(str) : 0;
- if (e && is_ascii_string(str)) {
- e = 0;
+ if (e && !is_ascii_string(str)) {
+ h = rb_hash_end(rb_hash_uint32(h, (uint32_t)e));
}
- return rb_memhash((const void *)RSTRING_PTR(str), RSTRING_LEN(str)) ^ e;
+ return h;
}
int