From 88e0c64ffc158a91a4d68a68b96e3df3260ab1b3 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 9 Apr 2022 09:26:39 +0900 Subject: [PATCH] class.c: fix bugs in inline method cache. --- src/class.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/class.c b/src/class.c index 68a0ff084..214aa0204 100644 --- a/src/class.c +++ b/src/class.c @@ -151,9 +151,11 @@ mt_get(mrb_state *mrb, mt_tbl *t, mrb_sym sym, union mt_ptr *pp) hash = kh_int_hash_func(mrb, sym); #ifdef MRB_USE_INLINE_METHOD_CACHE int cpos = (hash^(uintptr_t)t) % MT_CACHE_SIZE; + mrb_sym key; pos = mt_cache[cpos]; - if (cpos < t->alloc && t->table[cpos].key == sym) { - return &t->table[cpos]; + if (cpos < t->alloc && key = keys[pos] && MT_KEY_SYM(key) == sym) { + *pp = vals[pos]; + return key; } #endif start = pos = hash & (t->alloc-1); @@ -162,7 +164,7 @@ mt_get(mrb_state *mrb, mt_tbl *t, mrb_sym sym, union mt_ptr *pp) if (MT_KEY_SYM(key) == sym) { *pp = vals[pos]; #ifdef MRB_USE_INLINE_METHOD_CACHE - if (pos < 0xff) { + if (pos < 0x100) { mt_cache[cpos] = pos; } #endif