diff options
| author | Yukihiro Matsumoto <[email protected]> | 2012-06-01 01:25:16 +0900 |
|---|---|---|
| committer | Yukihiro Matsumoto <[email protected]> | 2012-06-01 01:25:16 +0900 |
| commit | 6a2cf46ff923a0969ba734f931fbdfbae6251929 (patch) | |
| tree | 0917a1df865a019e9f5cf3d4e2bb90f4c7525b00 | |
| parent | 3c80a5e2bf279d6ffc934d821885f5904f1baf7d (diff) | |
| download | mruby-6a2cf46ff923a0969ba734f931fbdfbae6251929.tar.gz mruby-6a2cf46ff923a0969ba734f931fbdfbae6251929.zip | |
hash function should use #hash internally
| -rw-r--r-- | src/hash.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/hash.c b/src/hash.c index 371ac777a..8cb039cea 100644 --- a/src/hash.c +++ b/src/hash.c @@ -21,11 +21,12 @@ static inline khint_t mrb_hash_ht_hash_func(mrb_state *mrb, mrb_value key) { - char type = mrb_type(key); - mrb_value s1 = mrb_str_new(mrb, &type, 1); - mrb_value s2 = mrb_inspect(mrb, key); - s1 = mrb_str_cat(mrb, s1, RSTRING_PTR(s2), RSTRING_LEN(s2)); - return kh_str_hash_func(mrb, RSTRING_PTR(s1)); + khint_t h = mrb_type(key) << 24; + mrb_value h2; + + h2 = mrb_funcall(mrb, key, "hash", 0, 0); + h ^= h2.value.i; + return h; } static inline khint_t |
