summaryrefslogtreecommitdiffhomepage
path: root/src/variable.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2018-12-11 09:47:06 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2018-12-11 09:47:06 +0900
commitf6b2e6231a1c07438915c2d32ab6002c2a2256b9 (patch)
tree61a0375a0008680d9f2843ac8917fba09f0ac878 /src/variable.c
parent378c728338c7dd828daf32468b4ce4f73fae4cb6 (diff)
downloadmruby-f6b2e6231a1c07438915c2d32ab6002c2a2256b9.tar.gz
mruby-f6b2e6231a1c07438915c2d32ab6002c2a2256b9.zip
Update `iv_foreach()` function.
* return `void` instead of `mrb_bool'. * non zero return value from `func` breaks the loop. * no longer remove items on negative return value from `func`.
Diffstat (limited to 'src/variable.c')
-rw-r--r--src/variable.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/variable.c b/src/variable.c
index 72c13aa1f..669a4f5cd 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -156,14 +156,13 @@ iv_del(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp)
}
/* Iterates over the instance variable table. */
-static mrb_bool
+static void
iv_foreach(mrb_state *mrb, iv_tbl *t, iv_foreach_func *func, void *p)
{
segment *seg;
size_t i;
- int n;
- if (t == NULL) return TRUE;
+ if (t == NULL) return;
seg = t->rootseg;
while (seg) {
for (i=0; i<MRB_IV_SEGMENT_SIZE; i++) {
@@ -171,20 +170,17 @@ iv_foreach(mrb_state *mrb, iv_tbl *t, iv_foreach_func *func, void *p)
/* no value in last segment after last_len */
if (!seg->next && i >= t->last_len) {
- return FALSE;
+ return;
}
if (key != 0) {
- n =(*func)(mrb, key, seg->val[i], p);
- if (n > 0) return FALSE;
- if (n < 0) {
- t->size--;
- seg->key[i] = 0;
+ if ((*func)(mrb, key, seg->val[i], p) != 0) {
+ return;
}
}
}
seg = seg->next;
}
- return TRUE;
+ return;
}
/* Get the size of the instance variable table. */