Skip to content

Commit f67294a

Browse files
committed
st: move out ST_CHECK from st_foreach
1 parent 25ba133 commit f67294a

File tree

2 files changed

+6
-26
lines changed

2 files changed

+6
-26
lines changed

ext/tk/tkutil/tkutil.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ to_strkey(key, value, hash)
266266
VALUE value;
267267
VALUE hash;
268268
{
269-
if (key == Qundef) return ST_CONTINUE;
270269
rb_hash_aset(hash, rb_funcall(key, ID_to_s, 0, 0), value);
271270
return ST_CHECK;
272271
}
@@ -280,7 +279,7 @@ tk_symbolkey2str(self, keys)
280279

281280
if NIL_P(keys) return new_keys;
282281
keys = rb_convert_type(keys, T_HASH, "Hash", "to_hash");
283-
st_foreach(RHASH_TBL(keys), to_strkey, new_keys);
282+
st_foreach_check(RHASH_TBL(keys), to_strkey, new_keys, Qundef);
284283
return new_keys;
285284
}
286285

@@ -653,7 +652,6 @@ push_kv(key, val, args)
653652

654653
ary = RARRAY_PTR(args)[0];
655654

656-
if (key == Qundef) return ST_CONTINUE;
657655
#if 0
658656
rb_ary_push(ary, key2keyname(key));
659657
if (val != TK_None) rb_ary_push(ary, val);
@@ -676,7 +674,7 @@ hash2kv(hash, ary, self)
676674
volatile VALUE dst = rb_ary_new2(2 * RHASH_SIZE(hash));
677675
volatile VALUE args = rb_ary_new3(2, dst, self);
678676

679-
st_foreach(RHASH_TBL(hash), push_kv, args);
677+
st_foreach_check(RHASH_TBL(hash), push_kv, args, Qundef);
680678

681679
if (NIL_P(ary)) {
682680
return dst;
@@ -695,7 +693,6 @@ push_kv_enc(key, val, args)
695693

696694
ary = RARRAY_PTR(args)[0];
697695

698-
if (key == Qundef) return ST_CONTINUE;
699696
#if 0
700697
rb_ary_push(ary, key2keyname(key));
701698
if (val != TK_None) {
@@ -721,7 +718,7 @@ hash2kv_enc(hash, ary, self)
721718
volatile VALUE dst = rb_ary_new2(2 * RHASH_SIZE(hash));
722719
volatile VALUE args = rb_ary_new3(2, dst, self);
723720

724-
st_foreach(RHASH_TBL(hash), push_kv_enc, args);
721+
st_foreach_check(RHASH_TBL(hash), push_kv_enc, args, Qundef);
725722

726723
if (NIL_P(ary)) {
727724
return dst;

st.c

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -970,20 +970,13 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
970970
retval = (*func)(key, val, arg);
971971
if (!table->entries_packed) {
972972
FIND_ENTRY(table, ptr, key, i);
973-
if (retval == ST_CHECK) {
974-
if (!ptr) goto deleted;
975-
goto unpacked_continue;
976-
}
973+
if (!ptr) return 0;
977974
goto unpacked;
978975
}
979976
switch (retval) {
980-
case ST_CHECK: /* check if hash is modified during iteration */
981-
if (i != find_packed_index(table, key)) {
982-
goto deleted;
983-
}
984-
/* fall through */
985977
case ST_CONTINUE:
986978
break;
979+
case ST_CHECK:
987980
case ST_STOP:
988981
return 0;
989982
case ST_DELETE:
@@ -1004,20 +997,10 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
1004997
retval = (*func)(ptr->key, ptr->record, arg);
1005998
unpacked:
1006999
switch (retval) {
1007-
case ST_CHECK: /* check if hash is modified during iteration */
1008-
for (tmp = table->bins[i]; tmp != ptr; tmp = tmp->next) {
1009-
if (!tmp) {
1010-
deleted:
1011-
/* call func with error notice */
1012-
retval = (*func)(0, 0, arg, 1);
1013-
return 1;
1014-
}
1015-
}
1016-
/* fall through */
10171000
case ST_CONTINUE:
1018-
unpacked_continue:
10191001
ptr = ptr->fore;
10201002
break;
1003+
case ST_CHECK:
10211004
case ST_STOP:
10221005
return 0;
10231006
case ST_DELETE:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy