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`.
parent 378c7283
...@@ -156,14 +156,13 @@ iv_del(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp) ...@@ -156,14 +156,13 @@ iv_del(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp)
} }
/* Iterates over the instance variable table. */ /* 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) iv_foreach(mrb_state *mrb, iv_tbl *t, iv_foreach_func *func, void *p)
{ {
segment *seg; segment *seg;
size_t i; size_t i;
int n;
if (t == NULL) return TRUE; if (t == NULL) return;
seg = t->rootseg; seg = t->rootseg;
while (seg) { while (seg) {
for (i=0; i<MRB_IV_SEGMENT_SIZE; i++) { 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) ...@@ -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 */ /* no value in last segment after last_len */
if (!seg->next && i >= t->last_len) { if (!seg->next && i >= t->last_len) {
return FALSE; return;
} }
if (key != 0) { if (key != 0) {
n =(*func)(mrb, key, seg->val[i], p); if ((*func)(mrb, key, seg->val[i], p) != 0) {
if (n > 0) return FALSE; return;
if (n < 0) {
t->size--;
seg->key[i] = 0;
} }
} }
} }
seg = seg->next; seg = seg->next;
} }
return TRUE; return;
} }
/* Get the size of the instance variable table. */ /* Get the size of the instance variable table. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment