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

ruby-changes:45448

From: normal <ko1@a...>
Date: Sat, 4 Feb 2017 08:55:10 +0900 (JST)
Subject: [ruby-changes:45448] normal:r57521 (trunk): symbol.c (rb_id2str): eliminate branch to set class

normal	2017-02-04 08:55:06 +0900 (Sat, 04 Feb 2017)

  New Revision: 57521

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

  Log:
    symbol.c (rb_id2str): eliminate branch to set class
    
    Since the fstring table encompasses all strings in the
    symbol table, we may reuse the fstring table walk to set
    the class and eliminate the branch in rb_id2str.
    
    * string.c (Init_String): use rb_cString immediately after definition
    * symbol.c (rb_id2str): eliminate branch to set class

  Modified files:
    trunk/string.c
    trunk/symbol.c
Index: symbol.c
===================================================================
--- symbol.c	(revision 57520)
+++ symbol.c	(revision 57521)
@@ -744,15 +744,7 @@ rb_sym2str(VALUE sym) https://github.com/ruby/ruby/blob/trunk/symbol.c#L744
 VALUE
 rb_id2str(ID id)
 {
-    VALUE str;
-
-    if ((str = lookup_id_str(id)) != 0) {
-        if (RBASIC(str)->klass == 0)
-            RBASIC_SET_CLASS_RAW(str, rb_cString);
-	return str;
-    }
-
-    return 0;
+    return lookup_id_str(id);
 }
 
 const char *
Index: string.c
===================================================================
--- string.c	(revision 57520)
+++ string.c	(revision 57521)
@@ -10036,6 +10036,8 @@ Init_String(void) https://github.com/ruby/ruby/blob/trunk/string.c#L10036
 #define rb_intern(str) rb_intern_const(str)
 
     rb_cString  = rb_define_class("String", rb_cObject);
+    assert(rb_vm_fstring_table());
+    st_foreach(rb_vm_fstring_table(), fstring_set_class_i, rb_cString);
     rb_include_module(rb_cString, rb_mComparable);
     rb_define_alloc_func(rb_cString, empty_str_alloc);
     rb_define_singleton_method(rb_cString, "try_convert", rb_str_s_try_convert, 1);
@@ -10215,7 +10217,4 @@ Init_String(void) https://github.com/ruby/ruby/blob/trunk/string.c#L10217
     rb_define_method(rb_cSymbol, "swapcase", sym_swapcase, -1);
 
     rb_define_method(rb_cSymbol, "encoding", sym_encoding, 0);
-
-    assert(rb_vm_fstring_table());
-    st_foreach(rb_vm_fstring_table(), fstring_set_class_i, rb_cString);
 }

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

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