Skip to content

Pack small hash tables (up to 6 entries) #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
st: move out ST_CHECK from st_foreach
  • Loading branch information
funny-falcon committed Mar 8, 2012
commit f67294a1bea36a63dc58442a604965c495140ae1
9 changes: 3 additions & 6 deletions ext/tk/tkutil/tkutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ to_strkey(key, value, hash)
VALUE value;
VALUE hash;
{
if (key == Qundef) return ST_CONTINUE;
rb_hash_aset(hash, rb_funcall(key, ID_to_s, 0, 0), value);
return ST_CHECK;
}
Expand All @@ -280,7 +279,7 @@ tk_symbolkey2str(self, keys)

if NIL_P(keys) return new_keys;
keys = rb_convert_type(keys, T_HASH, "Hash", "to_hash");
st_foreach(RHASH_TBL(keys), to_strkey, new_keys);
st_foreach_check(RHASH_TBL(keys), to_strkey, new_keys, Qundef);
return new_keys;
}

Expand Down Expand Up @@ -653,7 +652,6 @@ push_kv(key, val, args)

ary = RARRAY_PTR(args)[0];

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

st_foreach(RHASH_TBL(hash), push_kv, args);
st_foreach_check(RHASH_TBL(hash), push_kv, args, Qundef);

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

ary = RARRAY_PTR(args)[0];

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

st_foreach(RHASH_TBL(hash), push_kv_enc, args);
st_foreach_check(RHASH_TBL(hash), push_kv_enc, args, Qundef);

if (NIL_P(ary)) {
return dst;
Expand Down
23 changes: 3 additions & 20 deletions st.c
Original file line number Diff line number Diff line change
Expand Up @@ -970,20 +970,13 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
retval = (*func)(key, val, arg);
if (!table->entries_packed) {
FIND_ENTRY(table, ptr, key, i);
if (retval == ST_CHECK) {
if (!ptr) goto deleted;
goto unpacked_continue;
}
if (!ptr) return 0;
goto unpacked;
}
switch (retval) {
case ST_CHECK: /* check if hash is modified during iteration */
if (i != find_packed_index(table, key)) {
goto deleted;
}
/* fall through */
case ST_CONTINUE:
break;
case ST_CHECK:
case ST_STOP:
return 0;
case ST_DELETE:
Expand All @@ -1004,20 +997,10 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
retval = (*func)(ptr->key, ptr->record, arg);
unpacked:
switch (retval) {
case ST_CHECK: /* check if hash is modified during iteration */
for (tmp = table->bins[i]; tmp != ptr; tmp = tmp->next) {
if (!tmp) {
deleted:
/* call func with error notice */
retval = (*func)(0, 0, arg, 1);
return 1;
}
}
/* fall through */
case ST_CONTINUE:
unpacked_continue:
ptr = ptr->fore;
break;
case ST_CHECK:
case ST_STOP:
return 0;
case ST_DELETE:
Expand Down
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