aboutsummaryrefslogtreecommitdiffstats
path: root/st.c
diff options
context:
space:
mode:
authorglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-28 08:39:16 +0000
committerglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-28 08:39:16 +0000
commit79e63364953573d642537c0fe4eeeb03d85c15a7 (patch)
tree41a3a7ab413b31642d5f49cdb9cbcaafa6229527 /st.c
parent78cfcbc6577dda03fb4786743e63c7995c1b910b (diff)
downloadruby-79e63364953573d642537c0fe4eeeb03d85c15a7.tar.gz
* st.c: add st_values() and st_values_check().
* include/ruby/st.h: add prototypes for above. * hash.c (rb_hash_values): use st_values_check() for performance improvement if VALUE and st_data_t are compatible. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43895 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'st.c')
-rw-r--r--st.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/st.c b/st.c
index e04b2a1d19..163135912b 100644
--- a/st.c
+++ b/st.c
@@ -1132,6 +1132,47 @@ 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);
}
+static st_index_t
+get_values(st_table *table, st_data_t *values, st_index_t size, int check, st_data_t never)
+{
+ st_data_t key;
+ st_data_t *values_start = values;
+
+ if (table->entries_packed) {
+ st_index_t i;
+
+ if (size > table->real_entries) size = table->real_entries;
+ for (i = 0; i < size; i++) {
+ key = PKEY(table, i);
+ if (check && key == never) continue;
+ *values++ = PVAL(table, i);
+ }
+ }
+ else {
+ st_table_entry *ptr = table->head;
+ st_data_t *values_end = values + size;
+ for (; ptr && values < values_end; ptr = ptr->fore) {
+ key = ptr->key;
+ if (check && key == never) continue;
+ *values++ = ptr->record;
+ }
+ }
+
+ return values - values_start;
+}
+
+st_index_t
+st_values(st_table *table, st_data_t *values, st_index_t size)
+{
+ return get_values(table, values, size, 0, 0);
+}
+
+st_index_t
+st_values_check(st_table *table, st_data_t *values, st_index_t size, st_data_t never)
+{
+ return get_values(table, values, size, 1, never);
+}
+
#if 0 /* unused right now */
int
st_reverse_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)