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

ruby-changes:56201

From: Nobuyoshi <ko1@a...>
Date: Sun, 23 Jun 2019 01:58:00 +0900 (JST)
Subject: [ruby-changes:56201] Nobuyoshi Nakada: 5084233b88 (trunk): Split global search for module

https://git.ruby-lang.org/ruby.git/commit/?id=5084233b88

From 5084233b88cc48a74b58690423df1129668d5706 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 13 Dec 2018 18:27:32 +0900
Subject: Split global search for module


diff --git a/variable.c b/variable.c
index 6394e01..296e58a 100644
--- a/variable.c
+++ b/variable.c
@@ -2385,14 +2385,11 @@ rb_const_get_0(VALUE klass, ID id, int exclude, int recurse, int visibility) https://github.com/ruby/ruby/blob/trunk/variable.c#L2385
 }
 
 static VALUE
-rb_const_search(VALUE klass, ID id, int exclude, int recurse, int visibility)
+rb_const_search_from(VALUE klass, ID id, int exclude, int recurse, int visibility)
 {
-    VALUE value, tmp, av;
-    rb_const_flag_t flag;
-    int mod_retry = 0;
+    VALUE value, tmp;
 
     tmp = klass;
-  retry:
     while (RTEST(tmp)) {
 	VALUE am = 0;
 	rb_const_entry_t *ce;
@@ -2414,7 +2411,7 @@ rb_const_search(VALUE klass, ID id, int exclude, int recurse, int visibility) https://github.com/ruby/ruby/blob/trunk/variable.c#L2411
 		rb_autoload_load(tmp, id);
 		continue;
 	    }
-	    if (exclude && tmp == rb_cObject && klass != rb_cObject) {
+	    if (exclude && tmp == rb_cObject) {
 		goto not_found;
 	    }
 	    return value;
@@ -2422,17 +2419,26 @@ rb_const_search(VALUE klass, ID id, int exclude, int recurse, int visibility) https://github.com/ruby/ruby/blob/trunk/variable.c#L2419
 	if (!recurse) break;
 	tmp = RCLASS_SUPER(tmp);
     }
-    if (!exclude && !mod_retry && BUILTIN_TYPE(klass) == T_MODULE) {
-	mod_retry = 1;
-	tmp = rb_cObject;
-	goto retry;
-    }
 
   not_found:
     GET_EC()->private_const_reference = 0;
     return Qundef;
 }
 
+static VALUE
+rb_const_search(VALUE klass, ID id, int exclude, int recurse, int visibility)
+{
+    VALUE value;
+
+    if (klass == rb_cObject) exclude = FALSE;
+    value = rb_const_search_from(klass, id, exclude, recurse, visibility);
+    if (value != Qundef) return value;
+    if (exclude) return value;
+    if (BUILTIN_TYPE(klass) != T_MODULE) return value;
+    /* search global const too, if klass is a module */
+    return rb_const_search_from(rb_cObject, id, FALSE, recurse, visibility);
+}
+
 VALUE
 rb_const_get_from(VALUE klass, ID id)
 {
-- 
cgit v0.10.2


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

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