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

ruby-changes:39424

From: nobu <ko1@a...>
Date: Fri, 7 Aug 2015 21:04:39 +0900 (JST)
Subject: [ruby-changes:39424] nobu:r51505 (trunk): parse.y: shrink parser_params

nobu	2015-08-07 21:04:22 +0900 (Fri, 07 Aug 2015)

  New Revision: 51505

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

  Log:
    parse.y: shrink parser_params
    
    * parse.y (parser_params): turn in_def and in_single into bit
      flags and reduce the size by 2-words.

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51504)
+++ ChangeLog	(revision 51505)
@@ -1,4 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Fri Aug  7 17:30:19 2015  Nobuyoshi Nakada  <nobu@r...>
+Fri Aug  7 21:04:19 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (parser_params): turn in_def and in_single into bit
+	  flags and reduce the size by 2-words.
 
 	* parse.y (parser_params): remove redundant prefixes.
 
Index: parse.y
===================================================================
--- parse.y	(revision 51504)
+++ parse.y	(revision 51505)
@@ -250,8 +250,6 @@ struct parser_params { https://github.com/ruby/ruby/blob/trunk/parse.y#L250
     } lex;
     stack_type cond_stack;
     stack_type cmdarg_stack;
-    int in_single; /* counter */
-    int in_def; /* counter */
     int tokidx;
     int toksiz;
     int tokline;
@@ -277,6 +275,8 @@ struct parser_params { https://github.com/ruby/ruby/blob/trunk/parse.y#L275
     unsigned int in_defined: 1;
     unsigned int compile_for_eval: 1;
     unsigned int in_kwarg: 1;
+    unsigned int in_single: 1;
+    unsigned int in_def: 1;
 
 #ifndef RIPPER
     /* Ruby core only */
@@ -2956,27 +2956,24 @@ primary		: literal https://github.com/ruby/ruby/blob/trunk/parse.y#L2956
 		    }
 		| k_class tLSHFT expr
 		    {
-			$<num>$ = in_def;
+			$<num>$ = (in_def << 1) | in_single;
 			in_def = 0;
-		    }
-		  term
-		    {
-			$<num>$ = in_single;
 			in_single = 0;
 			local_push(0);
 		    }
+		  term
 		  bodystmt
 		  k_end
 		    {
 		    /*%%%*/
-			$$ = NEW_SCLASS($3, $7);
+			$$ = NEW_SCLASS($3, $6);
 			fixpos($$, $3);
 		    /*%
-			$$ = dispatch2(sclass, $3, $7);
+			$$ = dispatch2(sclass, $3, $6);
 		    %*/
 			local_pop();
-			in_def = $<num>4;
-			in_single = $<num>6;
+			in_def = ($<num>4 >> 1) & 1;
+			in_single = $<num>4 & 1;
 		    }
 		| k_module cpath
 		    {
@@ -3001,30 +2998,34 @@ primary		: literal https://github.com/ruby/ruby/blob/trunk/parse.y#L2998
 		    }
 		| k_def fname
 		    {
-			in_def++;
 			local_push(0);
 			$<id>$ = current_arg;
 			current_arg = 0;
 		    }
+		    {
+			$<num>$ = in_def;
+			in_def = 1;
+		    }
 		  f_arglist
 		  bodystmt
 		  k_end
 		    {
 		    /*%%%*/
-			NODE *body = remove_begin($5);
+			NODE *body = remove_begin($6);
 			reduce_nodes(&body);
-			$$ = NEW_DEFN($2, $4, body, METHOD_VISI_PRIVATE);
+			$$ = NEW_DEFN($2, $5, body, METHOD_VISI_PRIVATE);
 			nd_set_line($$, $<num>1);
 		    /*%
-			$$ = dispatch3(def, $2, $4, $5);
+			$$ = dispatch3(def, $2, $5, $6);
 		    %*/
 			local_pop();
-			in_def--;
+			in_def = $<num>4 & 1;
 			current_arg = $<id>3;
 		    }
 		| k_def singleton dot_or_colon {lex_state = EXPR_FNAME;} fname
 		    {
-			in_single++;
+			$<num>4 = in_single;
+			in_single = 1;
 			lex_state = EXPR_ENDFN; /* force for args */
 			local_push(0);
 			$<id>$ = current_arg;
@@ -3043,7 +3044,7 @@ primary		: literal https://github.com/ruby/ruby/blob/trunk/parse.y#L3044
 			$$ = dispatch5(defs, $2, $3, $5, $7, $8);
 		    %*/
 			local_pop();
-			in_single--;
+			in_single = $<num>4 & 1;
 			current_arg = $<id>6;
 		    }
 		| keyword_break

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

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