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

ruby-changes:36071

From: nobu <ko1@a...>
Date: Mon, 27 Oct 2014 15:16:29 +0900 (JST)
Subject: [ruby-changes:36071] nobu:r48152 (trunk): symbol.h: optimize ID2SYM

nobu	2014-10-27 15:16:16 +0900 (Mon, 27 Oct 2014)

  New Revision: 48152

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

  Log:
    symbol.h: optimize ID2SYM
    
    * symbol.h (rb_id2sym): optimize for predefined IDs.

  Modified files:
    trunk/symbol.c
    trunk/symbol.h
Index: symbol.c
===================================================================
--- symbol.c	(revision 48151)
+++ symbol.c	(revision 48152)
@@ -24,9 +24,7 @@ https://github.com/ruby/ruby/blob/trunk/symbol.c#L24
 
 #define SYMBOL_PINNED_P(sym) (RSYMBOL(sym)->id&~ID_SCOPE_MASK)
 
-#define DYNAMIC_ID_P(id) (!(id&ID_STATIC_SYM)&&id>tLAST_OP_ID)
 #define STATIC_SYM2ID(sym) RSHIFT((unsigned long)(sym), RUBY_SPECIAL_SHIFT)
-#define STATIC_ID2SYM(id)  (((VALUE)(id)<<RUBY_SPECIAL_SHIFT)|SYMBOL_FLAG)
 
 static ID register_static_symid(ID, const char *, long, rb_encoding *);
 static ID register_static_symid_str(ID, VALUE);
@@ -748,6 +746,7 @@ rb_sym2id(VALUE sym) https://github.com/ruby/ruby/blob/trunk/symbol.c#L746
     return id;
 }
 
+#undef rb_id2sym
 VALUE
 rb_id2sym(ID x)
 {
Index: symbol.h
===================================================================
--- symbol.h	(revision 48151)
+++ symbol.h	(revision 48152)
@@ -14,6 +14,15 @@ https://github.com/ruby/ruby/blob/trunk/symbol.h#L14
 
 #include "id.h"
 
+#define DYNAMIC_ID_P(id) (!(id&ID_STATIC_SYM)&&id>tLAST_OP_ID)
+#define STATIC_ID2SYM(id)  (((VALUE)(id)<<RUBY_SPECIAL_SHIFT)|SYMBOL_FLAG)
+
+#ifdef __GNUC__
+#define rb_id2sym(id) \
+    __extension__(__builtin_constant_p(id) && !DYNAMIC_ID_P(id) ? \
+		  STATIC_ID2SYM(id) : rb_id2sym(id))
+#endif
+
 struct RSymbol {
     struct RBasic basic;
     VALUE fstr;

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

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