summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-12-04 10:43:58 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2021-12-04 10:43:58 +0900
commite5810db1ad667c0c4aedce77a3643f64b20e1342 (patch)
treea751d6eedb161019cb672512495e45b8286ec35d
parent9d554017f08fd021471747071f43b5d3c7ddf49d (diff)
downloadmruby-e5810db1ad667c0c4aedce77a3643f64b20e1342.tar.gz
mruby-e5810db1ad667c0c4aedce77a3643f64b20e1342.zip
variable.c: reduce array access in iv hash table.
-rw-r--r--src/variable.c17
1 files changed, 10 insertions, 7 deletions
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);