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

ruby-changes:54990

From: nobu <ko1@a...>
Date: Sat, 9 Mar 2019 09:12:57 +0900 (JST)
Subject: [ruby-changes:54990] nobu:r67197 (trunk): variable.c: hoisted out rb_namespace_p

nobu	2019-03-09 09:12:52 +0900 (Sat, 09 Mar 2019)

  New Revision: 67197

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

  Log:
    variable.c: hoisted out rb_namespace_p

  Modified files:
    trunk/variable.c
Index: variable.c
===================================================================
--- variable.c	(revision 67196)
+++ variable.c	(revision 67197)
@@ -63,6 +63,16 @@ Init_var_tables(void) https://github.com/ruby/ruby/blob/trunk/variable.c#L63
     classid = rb_intern_const("__classid__");
 }
 
+static inline bool
+rb_namespace_p(VALUE obj)
+{
+    if (RB_SPECIAL_CONST_P(obj)) return false;
+    switch (RB_BUILTIN_TYPE(obj)) {
+      case T_MODULE: case T_CLASS: return true;
+    }
+    return false;
+}
+
 struct fc_result {
     ID name, preferred;
     VALUE klass;
@@ -110,7 +120,7 @@ fc_i(ID key, VALUE v, void *a) https://github.com/ruby/ruby/blob/trunk/variable.c#L120
 	res->path = fc_path(res, key);
 	return ID_TABLE_STOP;
     }
-    if (RB_TYPE_P(value, T_MODULE) || RB_TYPE_P(value, T_CLASS)) {
+    if (rb_namespace_p(value)) {
 	if (!RCLASS_CONST_TBL(value)) return ID_TABLE_CONTINUE;
 	else {
 	    struct fc_result arg;
@@ -423,7 +433,7 @@ rb_path_to_class(VALUE pathname) https://github.com/ruby/ruby/blob/trunk/variable.c#L433
 	}
 	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)) {
+	if (!rb_namespace_p(c)) {
 	    rb_raise(rb_eTypeError, "%"PRIsVALUE" does not refer to class/module",
 		     pathname);
 	}
@@ -2854,7 +2864,7 @@ rb_const_set(VALUE klass, ID id, VALUE v https://github.com/ruby/ruby/blob/trunk/variable.c#L2864
      * Resolve and cache class name immediately to resolve ambiguity
      * and avoid order-dependency on const_tbl
      */
-    if (rb_cObject && (RB_TYPE_P(val, T_MODULE) || RB_TYPE_P(val, T_CLASS))) {
+    if (rb_cObject && rb_namespace_p(val)) {
 	if (NIL_P(rb_class_path_cached(val))) {
 	    if (klass == rb_cObject) {
 		rb_ivar_set(val, classpath, rb_id2str(id));
@@ -3098,7 +3108,7 @@ cvar_front_klass(VALUE klass) https://github.com/ruby/ruby/blob/trunk/variable.c#L3108
 {
     if (FL_TEST(klass, FL_SINGLETON)) {
 	VALUE obj = rb_ivar_get(klass, id__attached__);
-	if (RB_TYPE_P(obj, T_MODULE) || RB_TYPE_P(obj, T_CLASS)) {
+	if (rb_namespace_p(obj)) {
 	    return obj;
 	}
     }

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

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