https://gcc.gnu.org/g:14fde9162dfdcd497f17fa799abce1146263893f

commit r15-7120-g14fde9162dfdcd497f17fa799abce1146263893f
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Wed Jan 22 09:24:34 2025 +0100

    c++: Improve cp_parser_objc_messsage_args compile time
    
    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.
    
    Verified also on the 2 va-meth*.mm testcases (one without CPP_EMBED, one
    with) that -fdump-tree-gimple is the same before/after the patch.
    
    2025-01-22  Jakub Jelinek  <ja...@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.

Diff:
---
 gcc/cp/parser.cc | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index a9eddd1a6da5..e1fa7e5ee221 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -36721,9 +36721,7 @@ cp_parser_objc_message_args (cp_parser* 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);
     }
@@ -36738,14 +36736,12 @@ cp_parser_objc_message_args (cp_parser* 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);
@@ -36757,7 +36753,7 @@ cp_parser_objc_message_args (cp_parser* 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.

Reply via email to