diff options
author | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-11-28 08:39:16 +0000 |
---|---|---|
committer | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-11-28 08:39:16 +0000 |
commit | 79e63364953573d642537c0fe4eeeb03d85c15a7 (patch) | |
tree | 41a3a7ab413b31642d5f49cdb9cbcaafa6229527 /hash.c | |
parent | 78cfcbc6577dda03fb4786743e63c7995c1b910b (diff) | |
download | ruby-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 'hash.c')
-rw-r--r-- | hash.c | 22 |
1 files changed, 18 insertions, 4 deletions
@@ -1746,12 +1746,26 @@ values_i(VALUE key, VALUE value, VALUE ary) VALUE rb_hash_values(VALUE hash) { - VALUE ary; + VALUE values; + st_index_t size = RHASH_SIZE(hash); - ary = rb_ary_new_capa(RHASH_SIZE(hash)); - rb_hash_foreach(hash, values_i, ary); + values = rb_ary_new_capa(size); + if (size == 0) return values; - return ary; + if (ST_DATA_COMPATIBLE_P(VALUE)) { + st_table *table = RHASH(hash)->ntbl; + + if (OBJ_PROMOTED(values)) rb_gc_writebarrier_remember_promoted(values); + RARRAY_PTR_USE(values, ptr, { + size = st_values_check(table, ptr, size, Qundef); + }); + rb_ary_set_len(values, size); + } + else { + rb_hash_foreach(hash, values_i, values); + } + + return values; } /* |