ruby-changes:31877
From: charliesome <ko1@a...>
Date: Mon, 2 Dec 2013 17:26:37 +0900 (JST)
Subject: [ruby-changes:31877] charliesome:r43956 (trunk): * variable.c (rb_mod_constants): when calling Module#constants with
charliesome 2013-12-02 17:26:29 +0900 (Mon, 02 Dec 2013) New Revision: 43956 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43956 Log: * variable.c (rb_mod_constants): when calling Module#constants with inherit=false, there is no need to use a hashtable to deduplicate constant names. [Feature #9196] [ruby-core:58786] Modified files: trunk/ChangeLog trunk/variable.c Index: ChangeLog =================================================================== --- ChangeLog (revision 43955) +++ ChangeLog (revision 43956) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Dec 2 17:23:00 2013 Charlie Somerville <charliesome@r...> + + * variable.c (rb_mod_constants): when calling Module#constants with + inherit=false, there is no need to use a hashtable to deduplicate + constant names. [Feature #9196] [ruby-core:58786] + Mon Dec 2 14:16:52 2013 Eric Hodel <drbrain@s...> * lib/net/smtp.rb (Net::SMTP#critical): Always return a Index: variable.c =================================================================== --- variable.c (revision 43955) +++ variable.c (revision 43956) @@ -1969,6 +1969,26 @@ sv_i(st_data_t k, st_data_t v, st_data_t https://github.com/ruby/ruby/blob/trunk/variable.c#L1969 return ST_CONTINUE; } +static int +rb_local_constants_i(st_data_t const_name, st_data_t const_value, st_data_t ary) +{ + rb_ary_push((VALUE)ary, ID2SYM((ID)const_name)); + return ST_CONTINUE; +} + +static VALUE +rb_local_constants(VALUE mod) +{ + st_table *tbl = RCLASS_CONST_TBL(mod); + VALUE ary; + + if (!tbl) return rb_ary_new2(0); + + ary = rb_ary_new2(tbl->num_entries); + st_foreach(tbl, rb_local_constants_i, ary); + return ary; +} + void* rb_mod_const_at(VALUE mod, void *data) { @@ -2037,7 +2057,6 @@ VALUE https://github.com/ruby/ruby/blob/trunk/variable.c#L2057 rb_mod_constants(int argc, VALUE *argv, VALUE mod) { VALUE inherit; - st_table *tbl; if (argc == 0) { inherit = Qtrue; @@ -2045,13 +2064,13 @@ rb_mod_constants(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/variable.c#L2064 else { rb_scan_args(argc, argv, "01", &inherit); } + if (RTEST(inherit)) { - tbl = rb_mod_const_of(mod, 0); + return rb_const_list(rb_mod_const_of(mod, 0)); } else { - tbl = rb_mod_const_at(mod, 0); + return rb_local_constants(mod); } - return rb_const_list(tbl); } static int -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/