diff options
author | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-10-10 12:06:01 +0000 |
---|---|---|
committer | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-10-10 12:06:01 +0000 |
commit | 026955e37517d07679ea8044d939400d6e9beaaf (patch) | |
tree | 0892965fb6152241df67902c60b6918a1f7cac13 /hash.c | |
parent | 4599d3efd7bfda591fd29e5647af2d5aa8be486c (diff) | |
download | ruby-026955e37517d07679ea8044d939400d6e9beaaf.tar.gz |
* st.c (st_keys): define st_keys() for performance improvement of
Hash#keys and Array#uniq.
* st.h: ditto.
* hash.c (rb_hash_keys): use st_keys().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 15 |
1 files changed, 3 insertions, 12 deletions
@@ -1663,13 +1663,6 @@ rb_hash_to_h(VALUE hash) return hash; } -static int -keys_i(VALUE key, VALUE value, VALUE ary) -{ - rb_ary_push(ary, key); - return ST_CONTINUE; -} - /* * call-seq: * hsh.keys -> array @@ -1685,12 +1678,10 @@ keys_i(VALUE key, VALUE value, VALUE ary) VALUE rb_hash_keys(VALUE hash) { - VALUE ary; - - ary = rb_ary_new_capa(RHASH_SIZE(hash)); - rb_hash_foreach(hash, keys_i, ary); + st_table *table = RHASH(hash)->ntbl; - return ary; + if (!table) return rb_ary_new(); + return st_keys(table); } static int |