diff mbox series

c++: Improve cp_parser_objc_messsage_args compile time

Message ID Z4/hTzNS8Dfyzsij@tucnak
State New
Headers show
Series c++: Improve cp_parser_objc_messsage_args compile time | expand

Commit Message

Jakub Jelinek Jan. 21, 2025, 6:02 p.m. UTC
On Tue, Jan 21, 2025 at 06:47:53PM +0100, Jakub Jelinek wrote:
> Indeed, I've just used what it was doing without thinking too much about it,
> sorry.
> addl_args = tree_cons (NULL_TREE, arg, addl_args);
> with addl_args = nreverse (addl_args); after the loop might be better,
> can test that incrementally.  sel_args is handled the same and should have
> the same treatment.

Here is incremental patch to do that.

So far verified on the 2 va-meth*.mm testcases (one without CPP_EMBED, one
with) that -fdump-tree-gimple is the same before/after the patch.

Ok for trunk if it passes bootstrap/regtest (or defer for GCC 16?)?

2025-01-21  Jakub Jelinek  <jakub@redhat.com>

	* parser.cc (cp_parser_objc_message_args): Use tree_cons with
	nreverse at the end for both sel_args and addl_args, instead of
	chainon with build_tree_list second argument.



	Jakub

Comments

Jason Merrill Jan. 21, 2025, 9:41 p.m. UTC | #1
On 1/21/25 1:02 PM, Jakub Jelinek wrote:
> On Tue, Jan 21, 2025 at 06:47:53PM +0100, Jakub Jelinek wrote:
>> Indeed, I've just used what it was doing without thinking too much about it,
>> sorry.
>> addl_args = tree_cons (NULL_TREE, arg, addl_args);
>> with addl_args = nreverse (addl_args); after the loop might be better,
>> can test that incrementally.  sel_args is handled the same and should have
>> the same treatment.
> 
> Here is incremental patch to do that.
> 
> So far verified on the 2 va-meth*.mm testcases (one without CPP_EMBED, one
> with) that -fdump-tree-gimple is the same before/after the patch.
> 
> Ok for trunk if it passes bootstrap/regtest (or defer for GCC 16?)?

OK.

> 2025-01-21  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* parser.cc (cp_parser_objc_message_args): Use tree_cons with
> 	nreverse at the end for both sel_args and addl_args, instead of
> 	chainon with build_tree_list second argument.
> 
> --- gcc/cp/parser.cc.jj	2025-01-21 18:49:42.478969570 +0100
> +++ gcc/cp/parser.cc	2025-01-21 18:52:19.035786901 +0100
> @@ -36724,9 +36724,7 @@ cp_parser_objc_message_args (cp_parser*
>         cp_parser_require (parser, CPP_COLON, RT_COLON);
>         arg = cp_parser_assignment_expression (parser);
>   
> -      sel_args
> -	= chainon (sel_args,
> -		   build_tree_list (selector, arg));
> +      sel_args = tree_cons (selector, arg, sel_args);
>   
>         token = cp_lexer_peek_token (parser->lexer);
>       }
> @@ -36741,14 +36739,12 @@ cp_parser_objc_message_args (cp_parser*
>   	  tree raw_data = cp_lexer_peek_token (parser->lexer)->u.value;
>   	  cp_lexer_consume_token (parser->lexer);
>   	  for (tree argument : raw_data_range (raw_data))
> -	    addl_args = chainon (addl_args,
> -				 build_tree_list (NULL_TREE, argument));
> +	    addl_args = tree_cons (NULL_TREE, argument, addl_args);
>   	}
>         else
>   	{
>   	  tree arg = cp_parser_assignment_expression (parser);
> -	  addl_args = chainon (addl_args,
> -			       build_tree_list (NULL_TREE, arg));
> +	  addl_args = tree_cons (NULL_TREE, arg, addl_args);
>   	}
>   
>         token = cp_lexer_peek_token (parser->lexer);
> @@ -36760,7 +36756,7 @@ cp_parser_objc_message_args (cp_parser*
>         return build_tree_list (error_mark_node, error_mark_node);
>       }
>   
> -  return build_tree_list (sel_args, addl_args);
> +  return build_tree_list (nreverse (sel_args), nreverse (addl_args));
>   }
>   
>   /* Parse an Objective-C encode expression.
> 
> 
> 	Jakub
>
diff mbox series

Patch

--- gcc/cp/parser.cc.jj	2025-01-21 18:49:42.478969570 +0100
+++ gcc/cp/parser.cc	2025-01-21 18:52:19.035786901 +0100
@@ -36724,9 +36724,7 @@  cp_parser_objc_message_args (cp_parser*
       cp_parser_require (parser, CPP_COLON, RT_COLON);
       arg = cp_parser_assignment_expression (parser);
 
-      sel_args
-	= chainon (sel_args,
-		   build_tree_list (selector, arg));
+      sel_args = tree_cons (selector, arg, sel_args);
 
       token = cp_lexer_peek_token (parser->lexer);
     }
@@ -36741,14 +36739,12 @@  cp_parser_objc_message_args (cp_parser*
 	  tree raw_data = cp_lexer_peek_token (parser->lexer)->u.value;
 	  cp_lexer_consume_token (parser->lexer);
 	  for (tree argument : raw_data_range (raw_data))
-	    addl_args = chainon (addl_args,
-				 build_tree_list (NULL_TREE, argument));
+	    addl_args = tree_cons (NULL_TREE, argument, addl_args);
 	}
       else
 	{
 	  tree arg = cp_parser_assignment_expression (parser);
-	  addl_args = chainon (addl_args,
-			       build_tree_list (NULL_TREE, arg));
+	  addl_args = tree_cons (NULL_TREE, arg, addl_args);
 	}
 
       token = cp_lexer_peek_token (parser->lexer);
@@ -36760,7 +36756,7 @@  cp_parser_objc_message_args (cp_parser*
       return build_tree_list (error_mark_node, error_mark_node);
     }
 
-  return build_tree_list (sel_args, addl_args);
+  return build_tree_list (nreverse (sel_args), nreverse (addl_args));
 }
 
 /* Parse an Objective-C encode expression.