ruby-changes:31164
From: nobu <ko1@a...>
Date: Fri, 11 Oct 2013 01:29:04 +0900 (JST)
Subject: [ruby-changes:31164] nobu:r43243 (trunk): st.c: revert st_keys
nobu 2013-10-11 01:28:56 +0900 (Fri, 11 Oct 2013) New Revision: 43243 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43243 Log: st.c: revert st_keys * st.c: revert st_keys() at r43238. VALUE cannot be in st.c. Modified files: trunk/ChangeLog trunk/hash.c trunk/include/ruby/st.h trunk/st.c Index: include/ruby/st.h =================================================================== --- include/ruby/st.h (revision 43242) +++ include/ruby/st.h (revision 43243) @@ -112,7 +112,6 @@ int st_update(st_table *table, st_data_t https://github.com/ruby/ruby/blob/trunk/include/ruby/st.h#L112 int st_foreach(st_table *, int (*)(ANYARGS), st_data_t); int st_foreach_check(st_table *, int (*)(ANYARGS), st_data_t, st_data_t); int st_reverse_foreach(st_table *, int (*)(ANYARGS), st_data_t); -VALUE st_keys(st_table *table); void st_add_direct(st_table *, st_data_t, st_data_t); void st_free_table(st_table *); void st_cleanup_safe(st_table *, st_data_t); Index: ChangeLog =================================================================== --- ChangeLog (revision 43242) +++ ChangeLog (revision 43243) @@ -10,15 +10,6 @@ Thu Oct 10 21:36:16 2013 Masaki Matsush https://github.com/ruby/ruby/blob/trunk/ChangeLog#L10 * array.c (rb_ary_compact_bang): use ary_resize_smaller(). -Thu Oct 10 21:00:38 2013 Masaki Matsushita <glass.saga@g...> - - * 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(). - Thu Oct 10 17:25:28 2013 Koichi Sasada <ko1@a...> * vm.c (vm_exec): support :b_return event for "lambda{return}.call". Index: st.c =================================================================== --- st.c (revision 43242) +++ st.c (revision 43243) @@ -1091,37 +1091,6 @@ st_foreach(st_table *table, int (*func)( https://github.com/ruby/ruby/blob/trunk/st.c#L1091 return 0; } -VALUE -st_keys(st_table *table) -{ - st_table_entry *ptr = NULL; - st_data_t key, never = (st_data_t)Qundef; - VALUE keys = rb_ary_new_capa(table->num_entries); - - if (table->entries_packed) { - st_index_t i; - - for (i = 0; i < table->real_entries; i++) { - key = PKEY(table, i); - if (key == never) continue; - rb_ary_push(keys, (VALUE)key); - } - } - else { - ptr = table->head; - } - - if (ptr != 0) { - do { - key = ptr->key; - if (key != never) rb_ary_push(keys, (VALUE)key); - ptr = ptr->fore; - } while (ptr && table->head); - } - - return keys; -} - #if 0 /* unused right now */ int st_reverse_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg) Index: hash.c =================================================================== --- hash.c (revision 43242) +++ hash.c (revision 43243) @@ -1663,6 +1663,13 @@ rb_hash_to_h(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L1663 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 @@ -1678,10 +1685,12 @@ rb_hash_to_h(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L1685 VALUE rb_hash_keys(VALUE hash) { - st_table *table = RHASH(hash)->ntbl; + VALUE ary; + + ary = rb_ary_new_capa(RHASH_SIZE(hash)); + rb_hash_foreach(hash, keys_i, ary); - if (!table) return rb_ary_new(); - return st_keys(table); + return ary; } static int -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/