From 79e63364953573d642537c0fe4eeeb03d85c15a7 Mon Sep 17 00:00:00 2001 From: glass Date: Thu, 28 Nov 2013 08:39:16 +0000 Subject: * 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 --- hash.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'hash.c') diff --git a/hash.c b/hash.c index b03c13dc13..e347c79192 100644 --- a/hash.c +++ b/hash.c @@ -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; } /* -- cgit v1.2.3