diff options
author | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-11-28 08:15:26 +0000 |
---|---|---|
committer | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-11-28 08:15:26 +0000 |
commit | 78cfcbc6577dda03fb4786743e63c7995c1b910b (patch) | |
tree | 4d88af75465582403e26d60330c18ad2a10b2a4f | |
parent | d7009f76ef8a7b96e73471561cf9c4863902e438 (diff) |
* st.c (st_keys): fix not to use Qundef in st.c.
* include/ruby/st.h: define modified prototype.
* hash.c (rb_hash_keys): use modified st_keys().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43894 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | hash.c | 2 | ||||
-rw-r--r-- | include/ruby/st.h | 1 | ||||
-rw-r--r-- | st.c | 26 |
4 files changed, 29 insertions, 8 deletions
@@ -1,3 +1,11 @@ +Thu Nov 28 17:14:14 2013 Masaki Matsushita <[email protected]> + + * st.c (st_keys): fix not to use Qundef in st.c. + + * include/ruby/st.h: define modified prototype. + + * hash.c (rb_hash_keys): use modified st_keys(). + Thu Nov 28 16:34:43 2013 Aman Gupta <[email protected]> * gc.c: Expose details about last garbage collection via GC.stat. @@ -1713,7 +1713,7 @@ rb_hash_keys(VALUE hash) if (OBJ_PROMOTED(keys)) rb_gc_writebarrier_remember_promoted(keys); RARRAY_PTR_USE(keys, ptr, { - size = st_keys(table, ptr, size); + size = st_keys_check(table, ptr, size, Qundef); }); rb_ary_set_len(keys, size); } diff --git a/include/ruby/st.h b/include/ruby/st.h index fa6190dcd6..839eb1ef0b 100644 --- a/include/ruby/st.h +++ b/include/ruby/st.h @@ -120,6 +120,7 @@ int st_foreach(st_table *, int (*)(ANYARGS), st_data_t); int st_foreach_check(st_table *, int (*)(ANYARGS), st_data_t, st_data_t); int st_reverse_foreach(st_table *, int (*)(ANYARGS), st_data_t); st_index_t st_keys(st_table *table, st_data_t *keys, st_index_t size); +st_index_t st_keys_check(st_table *table, st_data_t *keys, st_index_t size, st_data_t never); void st_add_direct(st_table *, st_data_t, st_data_t); void st_free_table(st_table *); void st_cleanup_safe(st_table *, st_data_t); @@ -1091,10 +1091,10 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg) return 0; } -st_index_t -st_keys(st_table *table, st_data_t *keys, st_index_t size) +static st_index_t +get_keys(st_table *table, st_data_t *keys, st_index_t size, int check, st_data_t never) { - st_data_t key, never = (st_data_t)Qundef; + st_data_t key; st_data_t *keys_start = keys; if (table->entries_packed) { @@ -1103,23 +1103,35 @@ st_keys(st_table *table, st_data_t *keys, st_index_t size) if (size > table->real_entries) size = table->real_entries; for (i = 0; i < size; i++) { key = PKEY(table, i); - if (key == never) continue; + if (check && key == never) continue; *keys++ = key; } } else { st_table_entry *ptr = table->head; st_data_t *keys_end = keys + size; - while (ptr && keys < keys_end) { + for (; ptr && keys < keys_end; ptr = ptr->fore) { key = ptr->key; - if (key != never) *keys++ = key; - ptr = ptr->fore; + if (check && key == never) continue; + *keys++ = key; } } return keys - keys_start; } +st_index_t +st_keys(st_table *table, st_data_t *keys, st_index_t size) +{ + return get_keys(table, keys, size, 0, 0); +} + +st_index_t +st_keys_check(st_table *table, st_data_t *keys, st_index_t size, st_data_t never) +{ + return get_keys(table, keys, size, 1, never); +} + #if 0 /* unused right now */ int st_reverse_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg) |