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

ruby-changes:32110

From: nobu <ko1@a...>
Date: Sat, 14 Dec 2013 10:50:53 +0900 (JST)
Subject: [ruby-changes:32110] nobu:r44189 (trunk): object.c: optimize rb_mod_const_get for symbol

nobu	2013-12-14 10:50:49 +0900 (Sat, 14 Dec 2013)

  New Revision: 44189

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44189

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

  Modified files:
    trunk/object.c
Index: object.c
===================================================================
--- object.c	(revision 44188)
+++ object.c	(revision 44189)
@@ -2074,7 +2074,6 @@ rb_mod_const_get(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/object.c#L2074
     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, https://github.com/ruby/ruby/blob/trunk/object.c#L2083
 	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, https://github.com/ruby/ruby/blob/trunk/object.c#L2106
     }
 
     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, https://github.com/ruby/ruby/blob/trunk/object.c#L2123
 	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, https://github.com/ruby/ruby/blob/trunk/object.c#L2150
 	    }
 	}
 	if (!rb_is_const_id(id)) {
+	  wrong_id:
 	    rb_name_error(id, "wrong constant name %"PRIsVALUE,
 			  QUOTE_ID(id));
 	}

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

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