[前][次][番号順一覧][スレッド一覧]

ruby-changes:43374

From: nobu <ko1@a...>
Date: Sun, 19 Jun 2016 10:54:48 +0900 (JST)
Subject: [ruby-changes:43374] nobu:r55448 (trunk): variable.c: rb_const_search

nobu	2016-06-19 10:54:42 +0900 (Sun, 19 Jun 2016)

  New Revision: 55448

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55448

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/variable.c
Index: variable.c
===================================================================
--- variable.c	(revision 55447)
+++ variable.c	(revision 55448)
@@ -25,6 +25,7 @@ static ID autoload, classpath, tmp_class https://github.com/ruby/ruby/blob/trunk/variable.c#L25
 
 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) https://github.com/ruby/ruby/blob/trunk/variable.c#L409
 	    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);
@@ -2238,6 +2240,14 @@ rb_const_warn_if_deprecated(const rb_con https://github.com/ruby/ruby/blob/trunk/variable.c#L2240
 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 e https://github.com/ruby/ruby/blob/trunk/variable.c#L2286
 	goto retry;
     }
 
-    return rb_const_missing(klass, ID2SYM(id));
+    return Qundef;
 }
 
 VALUE
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55447)
+++ ChangeLog	(revision 55448)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jun 19 10:54:40 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
 
 	* test/rubygems/test_gem_installer.rb: Fixed broken test with extension

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]