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

ruby-changes:48276

From: mame <ko1@a...>
Date: Tue, 24 Oct 2017 15:28:03 +0900 (JST)
Subject: [ruby-changes:48276] mame:r60391 (trunk): Avoid many type casts

mame	2017-10-24 15:27:58 +0900 (Tue, 24 Oct 2017)

  New Revision: 60391

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

  Log:
    Avoid many type casts
    
    The idiom `rb_gc_force_recycle((VALUE)...)` was used heavily.
    This change defines `rb_discard_nod(NODE*)` and allows C compiler to
    typecheck.

  Modified files:
    trunk/parse.y
Index: parse.y
===================================================================
--- parse.y	(revision 60390)
+++ parse.y	(revision 60391)
@@ -332,6 +332,12 @@ parser_set_line(NODE *n, int l) https://github.com/ruby/ruby/blob/trunk/parse.y#L332
     nd_set_line(n, l);
 }
 
+static inline void
+rb_discard_node(NODE *n)
+{
+    rb_gc_force_recycle((VALUE)n);
+}
+
 #ifndef RIPPER
 static inline void
 set_line_body(NODE *body, int line)
@@ -4565,7 +4571,7 @@ f_arg		: f_arg_item https://github.com/ruby/ruby/blob/trunk/parse.y#L4571
 			$$ = $1;
 			$$->nd_plen++;
 			$$->nd_next = block_append($$->nd_next, $3->nd_next, @1.first_column);
-			rb_gc_force_recycle((VALUE)$3);
+			rb_discard_node($3);
 		    /*%
 			$$ = rb_ary_push($1, get_value($3));
 		    %*/
@@ -6441,7 +6447,7 @@ parser_peek_variable_name(struct parser_ https://github.com/ruby/ruby/blob/trunk/parse.y#L6447
 static inline enum yytokentype
 parser_string_term(struct parser_params *parser, int func)
 {
-    rb_gc_force_recycle((VALUE)lex_strterm);
+    rb_discard_node(lex_strterm);
     lex_strterm = 0;
     if (func & STR_FUNC_REGEXP) {
 	set_yylval_num(regx_options());
@@ -6619,7 +6625,7 @@ parser_heredoc_restore(struct parser_par https://github.com/ruby/ruby/blob/trunk/parse.y#L6625
     heredoc_end = ruby_sourceline;
     ruby_sourceline = nd_line(here);
     dispose_string(here->nd_lit);
-    rb_gc_force_recycle((VALUE)here);
+    rb_discard_node(here);
     token_flush(parser);
 }
 
@@ -8979,11 +8985,11 @@ literal_concat_gen(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L8985
 	if (htype == NODE_STR) {
 	    if (!literal_concat0(parser, lit, tail->nd_lit)) {
 	      error:
-		rb_gc_force_recycle((VALUE)head);
-		rb_gc_force_recycle((VALUE)tail);
+		rb_discard_node(head);
+		rb_discard_node(tail);
 		return 0;
 	    }
-	    rb_gc_force_recycle((VALUE)tail);
+	    rb_discard_node(tail);
 	}
 	else {
 	    list_append(head, tail, column);
@@ -8995,7 +9001,7 @@ literal_concat_gen(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L9001
 	    if (!literal_concat0(parser, head->nd_lit, tail->nd_lit))
 		goto error;
 	    tail->nd_lit = head->nd_lit;
-	    rb_gc_force_recycle((VALUE)head);
+	    rb_discard_node(head);
 	    head = tail;
 	}
 	else if (NIL_P(tail->nd_lit)) {
@@ -9003,7 +9009,7 @@ literal_concat_gen(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L9009
 	    head->nd_alen += tail->nd_alen - 1;
 	    head->nd_next->nd_end->nd_next = tail->nd_next;
 	    head->nd_next->nd_end = tail->nd_next->nd_end;
-	    rb_gc_force_recycle((VALUE)tail);
+	    rb_discard_node(tail);
 	}
 	else if (htype == NODE_DSTR && (headlast = head->nd_next->nd_end->nd_head) &&
 		 nd_type(headlast) == NODE_STR) {
@@ -9280,8 +9286,8 @@ new_regexp_gen(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/parse.y#L9286
 		    }
 		    rb_str_resize(tail, 0);
 		    prev->nd_next = list->nd_next;
-		    rb_gc_force_recycle((VALUE)list->nd_head);
-		    rb_gc_force_recycle((VALUE)list);
+		    rb_discard_node(list->nd_head);
+		    rb_discard_node(list);
 		    list = prev;
 		}
 		else {

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

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