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

ruby-changes:36072

From: nobu <ko1@a...>
Date: Mon, 27 Oct 2014 15:23:26 +0900 (JST)
Subject: [ruby-changes:36072] nobu:r48153 (trunk): parse.y: optimize IDs in ripper

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

  New Revision: 48153

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

  Log:
    parse.y: optimize IDs in ripper
    
    * parse.y: optimize ripper_intern calls, ::, **, -@, +@, <=>, >=,
      <=, ==, ===, !=, =~, !~, <<, >>, and call.
    
    * parse.y: use initialized IDs, warn and warning.

  Modified files:
    trunk/defs/id.def
    trunk/parse.y
    trunk/symbol.c
    trunk/template/id.h.tmpl
Index: symbol.c
===================================================================
--- symbol.c	(revision 48152)
+++ symbol.c	(revision 48153)
@@ -50,6 +50,7 @@ static ID register_static_symid_str(ID, https://github.com/ruby/ruby/blob/trunk/symbol.c#L50
 #define tASET   RUBY_TOKEN(ASET)
 #define tLSHFT  RUBY_TOKEN(LSHFT)
 #define tRSHFT  RUBY_TOKEN(RSHFT)
+#define tCOLON2 RUBY_TOKEN(COLON2)
 
 static const struct {
     unsigned short token;
@@ -72,6 +73,7 @@ static const struct { https://github.com/ruby/ruby/blob/trunk/symbol.c#L73
     {tASET,	"[]="},
     {tLSHFT,	"<<"},
     {tRSHFT,	">>"},
+    {tCOLON2,   "::"},
 };
 
 #define op_tbl_count numberof(op_tbl)
Index: defs/id.def
===================================================================
--- defs/id.def	(revision 48152)
+++ defs/id.def	(revision 48153)
@@ -38,6 +38,7 @@ firstline, predefined = __LINE__+1, %[\ https://github.com/ruby/ruby/blob/trunk/defs/id.def#L38
   to_i
   bt
   bt_locations
+  call
 
   _                                                     UScore
   "/*NULL*/"                                            NULL
Index: parse.y
===================================================================
--- parse.y	(revision 48152)
+++ parse.y	(revision 48153)
@@ -1225,7 +1225,7 @@ stmt		: keyword_alias fitem {lex_state = https://github.com/ruby/ruby/blob/trunk/parse.y#L1225
 		| primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call
 		    {
 			value_expr($5);
-			$$ = new_attr_op_assign($1, ripper_intern("::"), $3, $4, $5);
+			$$ = new_attr_op_assign($1, ID2SYM(idCOLON2), $3, $4, $5);
 		    }
 		| backref tOP_ASGN command_call
 		    {
@@ -1425,7 +1425,7 @@ command		: fcall command_args       %pre https://github.com/ruby/ruby/blob/trunk/parse.y#L1425
 			$$ = NEW_CALL($1, $3, $4);
 			fixpos($$, $1);
 		    /*%
-			$$ = dispatch4(command_call, $1, ripper_intern("::"), $3, $4);
+			$$ = dispatch4(command_call, $1, ID2SYM(idCOLON2), $3, $4);
 		    %*/
 		    }
 		| primary_value tCOLON2 operation2 command_args cmd_brace_block
@@ -1436,7 +1436,7 @@ command		: fcall command_args       %pre https://github.com/ruby/ruby/blob/trunk/parse.y#L1436
 			$$ = $5;
 			fixpos($$, $1);
 		    /*%
-			$$ = dispatch4(command_call, $1, ripper_intern("::"), $3, $4);
+			$$ = dispatch4(command_call, $1, ID2SYM(idCOLON2), $3, $4);
 			$$ = method_add_block($$, $5);
 		    %*/
 		   }
@@ -1759,7 +1759,7 @@ lhs		: user_variable https://github.com/ruby/ruby/blob/trunk/parse.y#L1759
 		    /*%%%*/
 			$$ = attrset($1, $3);
 		    /*%
-			$$ = dispatch3(field, $1, ripper_intern("::"), $3);
+			$$ = dispatch3(field, $1, ID2SYM(idCOLON2), $3);
 		    %*/
 		    }
 		| primary_value '.' tCONSTANT
@@ -2019,7 +2019,7 @@ arg		: lhs '=' arg https://github.com/ruby/ruby/blob/trunk/parse.y#L2019
 		| primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg
 		    {
 			value_expr($5);
-			$$ = new_attr_op_assign($1, ripper_intern("::"), $3, $4, $5);
+			$$ = new_attr_op_assign($1, ID2SYM(idCOLON2), $3, $4, $5);
 		    }
 		| primary_value tCOLON2 tCONSTANT tOP_ASGN arg
 		    {
@@ -2126,7 +2126,7 @@ arg		: lhs '=' arg https://github.com/ruby/ruby/blob/trunk/parse.y#L2126
 		    /*%%%*/
 			$$ = call_bin_op($1, tPOW, $3);
 		    /*%
-			$$ = dispatch3(binary, $1, ripper_intern("**"), $3);
+			$$ = dispatch3(binary, $1, ID2SYM(idPow), $3);
 		    %*/
 		    }
 		| tUMINUS_NUM simple_numeric tPOW arg
@@ -2134,8 +2134,8 @@ arg		: lhs '=' arg https://github.com/ruby/ruby/blob/trunk/parse.y#L2134
 		    /*%%%*/
 			$$ = NEW_CALL(call_bin_op($2, tPOW, $4), tUMINUS, 0);
 		    /*%
-			$$ = dispatch3(binary, $2, ripper_intern("**"), $4);
-			$$ = dispatch2(unary, ripper_intern("-@"), $$);
+			$$ = dispatch3(binary, $2, ID2SYM(idPow), $4);
+			$$ = dispatch2(unary, ID2SYM(idUMinus), $$);
 		    %*/
 		    }
 		| tUPLUS arg
@@ -2143,7 +2143,7 @@ arg		: lhs '=' arg https://github.com/ruby/ruby/blob/trunk/parse.y#L2143
 		    /*%%%*/
 			$$ = call_uni_op($2, tUPLUS);
 		    /*%
-			$$ = dispatch2(unary, ripper_intern("+@"), $2);
+			$$ = dispatch2(unary, ID2SYM(idUPlus), $2);
 		    %*/
 		    }
 		| tUMINUS arg
@@ -2151,7 +2151,7 @@ arg		: lhs '=' arg https://github.com/ruby/ruby/blob/trunk/parse.y#L2151
 		    /*%%%*/
 			$$ = call_uni_op($2, tUMINUS);
 		    /*%
-			$$ = dispatch2(unary, ripper_intern("-@"), $2);
+			$$ = dispatch2(unary, ID2SYM(idUMinus), $2);
 		    %*/
 		    }
 		| arg '|' arg
@@ -2183,7 +2183,7 @@ arg		: lhs '=' arg https://github.com/ruby/ruby/blob/trunk/parse.y#L2183
 		    /*%%%*/
 			$$ = call_bin_op($1, tCMP, $3);
 		    /*%
-			$$ = dispatch3(binary, $1, ripper_intern("<=>"), $3);
+			$$ = dispatch3(binary, $1, ID2SYM(idCmp), $3);
 		    %*/
 		    }
 		| arg '>' arg
@@ -2199,7 +2199,7 @@ arg		: lhs '=' arg https://github.com/ruby/ruby/blob/trunk/parse.y#L2199
 		    /*%%%*/
 			$$ = call_bin_op($1, tGEQ, $3);
 		    /*%
-			$$ = dispatch3(binary, $1, ripper_intern(">="), $3);
+			$$ = dispatch3(binary, $1, ID2SYM(idGE), $3);
 		    %*/
 		    }
 		| arg '<' arg
@@ -2215,7 +2215,7 @@ arg		: lhs '=' arg https://github.com/ruby/ruby/blob/trunk/parse.y#L2215
 		    /*%%%*/
 			$$ = call_bin_op($1, tLEQ, $3);
 		    /*%
-			$$ = dispatch3(binary, $1, ripper_intern("<="), $3);
+			$$ = dispatch3(binary, $1, ID2SYM(idLE), $3);
 		    %*/
 		    }
 		| arg tEQ arg
@@ -2223,7 +2223,7 @@ arg		: lhs '=' arg https://github.com/ruby/ruby/blob/trunk/parse.y#L2223
 		    /*%%%*/
 			$$ = call_bin_op($1, tEQ, $3);
 		    /*%
-			$$ = dispatch3(binary, $1, ripper_intern("=="), $3);
+			$$ = dispatch3(binary, $1, ID2SYM(idEq), $3);
 		    %*/
 		    }
 		| arg tEQQ arg
@@ -2231,7 +2231,7 @@ arg		: lhs '=' arg https://github.com/ruby/ruby/blob/trunk/parse.y#L2231
 		    /*%%%*/
 			$$ = call_bin_op($1, tEQQ, $3);
 		    /*%
-			$$ = dispatch3(binary, $1, ripper_intern("==="), $3);
+			$$ = dispatch3(binary, $1, ID2SYM(idEqq), $3);
 		    %*/
 		    }
 		| arg tNEQ arg
@@ -2239,7 +2239,7 @@ arg		: lhs '=' arg https://github.com/ruby/ruby/blob/trunk/parse.y#L2239
 		    /*%%%*/
 			$$ = call_bin_op($1, tNEQ, $3);
 		    /*%
-			$$ = dispatch3(binary, $1, ripper_intern("!="), $3);
+			$$ = dispatch3(binary, $1, ID2SYM(idNeq), $3);
 		    %*/
 		    }
 		| arg tMATCH arg
@@ -2250,7 +2250,7 @@ arg		: lhs '=' arg https://github.com/ruby/ruby/blob/trunk/parse.y#L2250
                             $$ = reg_named_capture_assign($1->nd_lit, $$);
                         }
 		    /*%
-			$$ = dispatch3(binary, $1, ripper_intern("=~"), $3);
+			$$ = dispatch3(binary, $1, ID2SYM(idEqTilde), $3);
 		    %*/
 		    }
 		| arg tNMATCH arg
@@ -2258,7 +2258,7 @@ arg		: lhs '=' arg https://github.com/ruby/ruby/blob/trunk/parse.y#L2258
 		    /*%%%*/
 			$$ = call_bin_op($1, tNMATCH, $3);
 		    /*%
-			$$ = dispatch3(binary, $1, ripper_intern("!~"), $3);
+			$$ = dispatch3(binary, $1, ID2SYM(idNeqTilde), $3);
 		    %*/
 		    }
 		| '!' arg
@@ -2282,7 +2282,7 @@ arg		: lhs '=' arg https://github.com/ruby/ruby/blob/trunk/parse.y#L2282
 		    /*%%%*/
 			$$ = call_bin_op($1, tLSHFT, $3);
 		    /*%
-			$$ = dispatch3(binary, $1, ripper_intern("<<"), $3);
+			$$ = dispatch3(binary, $1, ID2SYM(idLTLT), $3);
 		    %*/
 		    }
 		| arg tRSHFT arg
@@ -2290,7 +2290,7 @@ arg		: lhs '=' arg https://github.com/ruby/ruby/blob/trunk/parse.y#L2290
 		    /*%%%*/
 			$$ = call_bin_op($1, tRSHFT, $3);
 		    /*%
-			$$ = dispatch3(binary, $1, ripper_intern(">>"), $3);
+			$$ = dispatch3(binary, $1, ID2SYM(idGTGT), $3);
 		    %*/
 		    }
 		| arg tANDOP arg
@@ -3643,7 +3643,7 @@ method_call	: fcall paren_args https://github.com/ruby/ruby/blob/trunk/parse.y#L3643
 		    /*%%%*/
 			$$ = NEW_CALL($1, $3, 0);
 		    /*%
-			$$ = dispatch3(call, $1, ripper_intern("::"), $3);
+			$$ = dispatch3(call, $1, ID2SYM(idCOLON2), $3);
 		    %*/
 		    }
 		| primary_value '.'
@@ -3655,11 +3655,11 @@ method_call	: fcall paren_args https://github.com/ruby/ruby/blob/trunk/parse.y#L3655
 		  paren_args
 		    {
 		    /*%%%*/
-			$$ = NEW_CALL($1, rb_intern("call"), $4);
+			$$ = NEW_CALL($1, idCall, $4);
 			nd_set_line($$, $<num>3);
 		    /*%
 			$$ = dispatch3(call, $1, ripper_id2sym('.'),
-				       ripper_intern("call"));
+				       ID2SYM(idCall));
 			$$ = method_optarg($$, $4);
 		    %*/
 		    }
@@ -3672,11 +3672,11 @@ method_call	: fcall paren_args https://github.com/ruby/ruby/blob/trunk/parse.y#L3672
 		  paren_args
 		    {
 		    /*%%%*/
-			$$ = NEW_CALL($1, rb_intern("call"), $4);
+			$$ = NEW_CALL($1, idCall, $4);
 			nd_set_line($$, $<num>3);
 		    /*%
-			$$ = dispatch3(call, $1, ripper_intern("::"),
-				       ripper_intern("call"));
+			$$ = dispatch3(call, $1, ID2SYM(idCOLON2),
+				       ID2SYM(idCall));
 			$$ = method_optarg($$, $4);
 		    %*/
 		    }
@@ -4327,7 +4327,7 @@ numeric 	: simple_numeric https://github.com/ruby/ruby/blob/trunk/parse.y#L4327
 			$$ = $2;
 			$$->nd_lit = negate_lit($$->nd_lit);
 		    /*%
-			$$ = dispatch2(unary, ripper_intern("-@"), $2);
+			$$ = dispatch2(unary, ID2SYM(idUMinus), $2);
 		    %*/
 		    }
 		;
@@ -10774,16 +10774,18 @@ ripper_compile_error(struct parser_param https://github.com/ruby/ruby/blob/trunk/parse.y#L10774
     ripper_error_gen(parser);
 }
 
+static ID id_warn, id_warning;
+
 static void
 ripper_warn0(struct parser_params *parser, const char *fmt)
 {
-    rb_funcall(parser->value, rb_intern("warn"), 1, STR_NEW2(fmt));
+    rb_funcall(parser->value, id_warn, 1, STR_NEW2(fmt));
 }
 
 static void
 ripper_warnI(struct parser_params *parser, const char *fmt, int a)
 {
-    rb_funcall(parser->value, rb_intern("warn"), 2,
+    rb_funcall(parser->value, id_warn, 2,
                STR_NEW2(fmt), INT2NUM(a));
 }
 
@@ -10791,7 +10793,7 @@ ripper_warnI(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L10793
 static void
 ripper_warnS(struct parser_params *parser, const char *fmt, const char *str)
 {
-    rb_funcall(parser->value, rb_intern("warn"), 2,
+    rb_funcall(parser->value, id_warn, 2,
                STR_NEW2(fmt), STR_NEW2(str));
 }
 #endif
@@ -10799,27 +10801,27 @@ ripper_warnS(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L10801
 static void
 ripper_warnV(struct parser_params *parser, const char *fmt, VALUE v)
 {
-    rb_funcall(parser->value, rb_intern("warn"), 2,
+    rb_funcall(parser->value, id_warn, 2,
                STR_NEW2(fmt), v);
 }
 
 static void
 ripper_warning0(struct parser_params *parser, const char *fmt)
 {
-    rb_funcall(parser->value, rb_intern("warning"), 1, STR_NEW2(fmt));
+    rb_funcall(parser->value, id_warning, 1, STR_NEW2(fmt));
 }
 
 static void
 ripper_warningS(struct parser_params *parser, const char *fmt, const char *str)
 {
-    rb_funcall(parser->value, rb_intern("warning"), 2,
+    rb_funcall(parser->value, id_warning, 2,
                STR_NEW2(fmt), STR_NEW2(str));
 }
 
 static void
 ripper_warningV(struct parser_params *parser, const char *fmt, VALUE v)
 {
-    rb_funcall(parser->value, rb_intern("warning"), 2,
+    rb_funcall(parser->value, id_warning, 2,
                STR_NEW2(fmt), v);
 }
 
@@ -11027,9 +11029,8 @@ Init_ripper(void) https://github.com/ruby/ruby/blob/trunk/parse.y#L11029
 {
     ripper_init_eventids1();
     ripper_init_eventids2();
-    /* ensure existing in symbol table */
-    (void)rb_intern("||");
-    (void)rb_intern("&&");
+    id_warn = rb_intern_const("warn");
+    id_warning = rb_intern_const("warning");
 
     InitVM(ripper);
 }
Index: template/id.h.tmpl
===================================================================
--- template/id.h.tmpl	(revision 48152)
+++ template/id.h.tmpl	(revision 48153)
@@ -80,6 +80,7 @@ enum ruby_method_ids { https://github.com/ruby/ruby/blob/trunk/template/id.h.tmpl#L80
     idLTLT = RUBY_TOKEN(LSHFT),
     idLE = RUBY_TOKEN(LEQ),
     idGT = '>',
+    idGTGT = RUBY_TOKEN(RSHFT),
     idGE = RUBY_TOKEN(GEQ),
     idEq = RUBY_TOKEN(EQ),
     idEqq = RUBY_TOKEN(EQQ),
@@ -90,6 +91,7 @@ enum ruby_method_ids { https://github.com/ruby/ruby/blob/trunk/template/id.h.tmpl#L91
     idNeqTilde = RUBY_TOKEN(NMATCH),
     idAREF = RUBY_TOKEN(AREF),
     idASET = RUBY_TOKEN(ASET),
+    idCOLON2 = RUBY_TOKEN(COLON2),
     tPRESERVED_ID_BEGIN = <%=op_id_offset + token_op_ids.size - 1%>,
 % ids[:preserved].each do |token|
     id<%=token%>,

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

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