summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-04-10 00:14:57 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-04-10 00:14:57 +0900
commit020116fa6b467ad01dc22de494ce09065251073b (patch)
tree50154444febeb81239dafa4706bdfa9389fd09e4 /include
parent90e1a4fb566e030fac0dc4d00cd47227d72e2fff (diff)
downloadmruby-020116fa6b467ad01dc22de494ce09065251073b.tar.gz
mruby-020116fa6b467ad01dc22de494ce09065251073b.zip
revert 40eaf705 for performance reason; ref #2022
Diffstat (limited to 'include')
-rw-r--r--include/mruby/khash.h9
1 files changed, 5 insertions, 4 deletions
diff --git a/include/mruby/khash.h b/include/mruby/khash.h
index a2e6ef6f7..f0be03402 100644
--- a/include/mruby/khash.h
+++ b/include/mruby/khash.h
@@ -44,6 +44,7 @@ static const uint8_t __m_either[] = {0x03, 0x0c, 0x30, 0xc0};
v |= v >> 16;\
v++;\
} while (0)
+#define khash_mask(h) ((h)->n_buckets-1)
#define khash_inc(h) ((h)->n_buckets/2-1)
#define khash_upper_bound(h) (UPPER_BOUND((h)->n_buckets))
@@ -132,13 +133,13 @@ kh_fill_flags(uint8_t *p, uint8_t c, size_t len)
} \
khint_t kh_get_##name(mrb_state *mrb, kh_##name##_t *h, khkey_t key) \
{ \
- khint_t k = __hash_func(mrb,key) % h->n_buckets; \
+ khint_t k = __hash_func(mrb,key) & khash_mask(h); \
(void)mrb; \
while (!__ac_isempty(h->ed_flags, k)) { \
if (!__ac_isdel(h->ed_flags, k)) { \
if (__hash_equal(mrb,h->keys[k], key)) return k; \
} \
- k = (k+khash_inc(h)) % h->n_buckets; \
+ k = (k+khash_inc(h)) & khash_mask(h); \
} \
return kh_end(h); \
} \
@@ -171,10 +172,10 @@ kh_fill_flags(uint8_t *p, uint8_t c, size_t len)
if (h->n_occupied >= khash_upper_bound(h)) { \
kh_resize_##name(mrb, h, h->n_buckets*2); \
} \
- k = __hash_func(mrb,key) % h->n_buckets; \
+ k = __hash_func(mrb,key) & khash_mask(h); \
while (!__ac_iseither(h->ed_flags, k)) { \
if (__hash_equal(mrb,h->keys[k], key)) break; \
- k = (k+khash_inc(h)) % h->n_buckets; \
+ k = (k+khash_inc(h)) & khash_mask(h); \
} \
if (__ac_isempty(h->ed_flags, k)) { \
/* put at empty */ \