aboutsummaryrefslogtreecommitdiffstats
path: root/st.c
diff options
context:
space:
mode:
authorglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-28 08:15:26 +0000
committerglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-28 08:15:26 +0000
commit78cfcbc6577dda03fb4786743e63c7995c1b910b (patch)
tree4d88af75465582403e26d60330c18ad2a10b2a4f /st.c
parentd7009f76ef8a7b96e73471561cf9c4863902e438 (diff)
downloadruby-78cfcbc6577dda03fb4786743e63c7995c1b910b.tar.gz
* 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
Diffstat (limited to 'st.c')
-rw-r--r--st.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/st.c b/st.c
index 1fbf1f5e7c..e04b2a1d19 100644
--- a/st.c
+++ b/st.c
@@ -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)