summaryrefslogtreecommitdiff
path: root/variable.c
diff options
context:
space:
mode:
authorcharliesome <charliesome@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-02 08:26:29 +0000
committercharliesome <charliesome@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-02 08:26:29 +0000
commit39a8519a569bd2190422c4a340950ccd5bbc7f04 (patch)
treea557ff246e14894fae9bccdf0f9f15b35bcbb9c8 /variable.c
parent01b1f004618b67f2e3033e055cb3a87f05fd3fa6 (diff)
* 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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43956 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/variable.c b/variable.c
index a1bb36e..c65fdcb 100644
--- a/variable.c
+++ b/variable.c
@@ -1969,6 +1969,26 @@ sv_i(st_data_t k, st_data_t v, st_data_t a)
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
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, VALUE mod)
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