1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

variable.c: rb_const_search

* variable.c (rb_path_to_class): search the constant at once
  instead of checking if defined and then getting it.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-06-19 01:54:42 +00:00
parent 60857ce1a5
commit 5707ba30aa
2 changed files with 18 additions and 3 deletions

View file

@ -1,3 +1,8 @@
Sun Jun 19 10:54:40 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* variable.c (rb_path_to_class): search the constant at once
instead of checking if defined and then getting it.
Sat Jun 18 14:01:40 2016 SHIBATA Hiroshi <hsbt@ruby-lang.org>
* test/rubygems/test_gem_installer.rb: Fixed broken test with extension

View file

@ -25,6 +25,7 @@ static ID autoload, classpath, tmp_classpath, classid;
static void check_before_mod_set(VALUE, ID, VALUE, const char *);
static void setup_const_entry(rb_const_entry_t *, VALUE, VALUE, rb_const_flag_t);
static VALUE rb_const_search(VALUE klass, ID id, int exclude, int recurse, int visibility);
static st_table *generic_iv_tbl;
static st_table *generic_iv_tbl_compat;
@ -408,12 +409,13 @@ rb_path_to_class(VALUE pathname)
p += 2;
pbeg = p;
}
if (!id || !rb_const_defined_at(c, id)) {
if (!id) {
undefined_class:
rb_raise(rb_eArgError, "undefined class/module % "PRIsVALUE,
rb_str_subseq(pathname, 0, p-path));
}
c = rb_const_get_at(c, id);
c = rb_const_search(c, id, TRUE, FALSE, FALSE);
if (c == Qundef) goto undefined_class;
if (!RB_TYPE_P(c, T_MODULE) && !RB_TYPE_P(c, T_CLASS)) {
rb_raise(rb_eTypeError, "%"PRIsVALUE" does not refer to class/module",
pathname);
@ -2237,6 +2239,14 @@ rb_const_warn_if_deprecated(const rb_const_entry_t *ce, VALUE klass, ID id)
static VALUE
rb_const_get_0(VALUE klass, ID id, int exclude, int recurse, int visibility)
{
VALUE c = rb_const_search(klass, id, exclude, recurse, visibility);
if (c != Qundef) return c;
return rb_const_missing(klass, ID2SYM(id));
}
static VALUE
rb_const_search(VALUE klass, ID id, int exclude, int recurse, int visibility)
{
VALUE value, tmp, av;
int mod_retry = 0;
@ -2276,7 +2286,7 @@ rb_const_get_0(VALUE klass, ID id, int exclude, int recurse, int visibility)
goto retry;
}
return rb_const_missing(klass, ID2SYM(id));
return Qundef;
}
VALUE