diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-08-10 08:37:05 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-08-10 08:47:01 +0900 |
| commit | 3d288ef0d87d065d09f7bdc72179476e5c03cedc (patch) | |
| tree | a0a7b69baf8c8e5ba06b0b18797a712eb528ca62 /src | |
| parent | 78be0172f74e2bf109f7a216e43257ba3eb8ecc4 (diff) | |
| download | mruby-3d288ef0d87d065d09f7bdc72179476e5c03cedc.tar.gz mruby-3d288ef0d87d065d09f7bdc72179476e5c03cedc.zip | |
Use standard hash functions in `mrb_hash_ht_hash_func`.
Diffstat (limited to 'src')
| -rw-r--r-- | src/hash.c | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/src/hash.c b/src/hash.c index f7e84463d..93d550187 100644 --- a/src/hash.c +++ b/src/hash.c @@ -20,37 +20,27 @@ mrb_hash_ht_hash_func(mrb_state *mrb, mrb_value key) { enum mrb_vtype t = mrb_type(key); mrb_value hv; - const char *p; - mrb_int i, len; khint_t h; switch (t) { case MRB_TT_STRING: - p = RSTRING_PTR(key); - len = RSTRING_LEN(key); - h = 0; - for (i=0; i<len; i++) { - h = (h << 5) - h + *p++; - } - return h; + h = mrb_str_hash(mrb, key); + break; + case MRB_TT_TRUE: + case MRB_TT_FALSE: case MRB_TT_SYMBOL: - h = (khint_t)mrb_symbol(key); - return kh_int_hash_func(mrb, h); - case MRB_TT_FIXNUM: - h = (khint_t)mrb_float_id((mrb_float)mrb_fixnum(key)); - return kh_int_hash_func(mrb, h); - case MRB_TT_FLOAT: - h = (khint_t)mrb_float_id(mrb_float(key)); - return kh_int_hash_func(mrb, h); + h = (khint_t)mrb_obj_id(key); + break; default: hv = mrb_funcall(mrb, key, "hash", 0); h = (khint_t)t ^ mrb_fixnum(hv); - return kh_int_hash_func(mrb, h); + break; } + return kh_int_hash_func(mrb, h); } static inline khint_t |
