From e5810db1ad667c0c4aedce77a3643f64b20e1342 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 4 Dec 2021 10:43:58 +0900 Subject: variable.c: reduce array access in iv hash table. --- src/variable.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/variable.c') diff --git a/src/variable.c b/src/variable.c index 2d3431e13..de740845b 100644 --- a/src/variable.c +++ b/src/variable.c @@ -78,16 +78,17 @@ iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val) hash = kh_int_hash_func(mrb, sym); start = pos = hash & (t->alloc-1); for (;;) { - if (keys[pos] == sym) { + mrb_sym key = keys[pos]; + if (key == sym) { vals[pos] = val; return; } - else if (keys[pos] == IV_EMPTY) { + else if (key == IV_EMPTY) { keys[pos] = sym; vals[pos] = val; return; } - else if (keys[pos] == IV_DELETED && dpos < 0) { + else if (key == IV_DELETED && dpos < 0) { dpos = pos; } pos = (pos+1) & (t->alloc-1); @@ -120,11 +121,12 @@ iv_get(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp) hash = kh_int_hash_func(mrb, sym); start = pos = hash & (t->alloc-1); for (;;) { - if (keys[pos] == sym) { + mrb_sym key = keys[pos]; + if (key == sym) { if (vp) *vp = vals[pos]; return TRUE; } - else if (keys[pos] == IV_EMPTY) { + else if (key == IV_EMPTY) { return FALSE; } pos = (pos+1) & (t->alloc-1); @@ -148,12 +150,13 @@ iv_del(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp) hash = kh_int_hash_func(mrb, sym); start = pos = hash & (t->alloc-1); for (;;) { - if (keys[pos] == sym) { + mrb_sym key = keys[pos]; + if (key == sym) { if (vp) *vp = vals[pos]; keys[pos] = IV_DELETED; return TRUE; } - else if (keys[pos] == IV_EMPTY) { + else if (key == IV_EMPTY) { return FALSE; } pos = (pos+1) & (t->alloc-1); -- cgit v1.2.3