summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-14 01:50:49 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-14 01:50:49 +0000
commit33fddfe585542a06761298fcd56a5ff8d63cc3bb (patch)
treec6d7ea4edaf7d596955fa25602d23e133318f704
parentc0abb5e5c376e9ac98fae33b692e89af3f49e2e1 (diff)
object.c: optimize rb_mod_const_get for symbol
* object.c (rb_mod_const_get): Symbol must be the entire name, not a nested constant path, so achieve by its ID directly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--object.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/object.c b/object.c
index 346a2cd..fce1ea3 100644
--- a/object.c
+++ b/object.c
@@ -2074,7 +2074,6 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod)
rb_encoding *enc;
const char *pbeg, *p, *path, *pend;
ID id;
- int nestable = 1;
if (argc == 1) {
name = argv[0];
@@ -2084,14 +2083,12 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod)
rb_scan_args(argc, argv, "11", &name, &recur);
}
- if (SYMBOL_P(name)) {
- name = rb_sym_to_s(name);
- nestable = 0;
+ id = rb_check_id(&name);
+ if (id) {
+ if (!rb_is_const_id(id)) goto wrong_id;
+ return RTEST(recur) ? rb_const_get(mod, id) : rb_const_get_at(mod, id);
}
- name = rb_check_string_type(name);
- Check_Type(name, T_STRING);
-
enc = rb_enc_get(name);
path = RSTRING_PTR(name);
@@ -2109,7 +2106,6 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod)
}
if (p + 2 < pend && p[0] == ':' && p[1] == ':') {
- if (!nestable) goto wrong_name;
mod = rb_cObject;
p += 2;
pbeg = p;
@@ -2127,7 +2123,6 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod)
beglen = pbeg-path;
if (p < pend && p[0] == ':') {
- if (!nestable) goto wrong_name;
if (p + 2 >= pend || p[1] != ':') goto wrong_name;
p += 2;
pbeg = p;
@@ -2155,6 +2150,7 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod)
}
}
if (!rb_is_const_id(id)) {
+ wrong_id:
rb_name_error(id, "wrong constant name %"PRIsVALUE,
QUOTE_ID(id));
}