This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Avoid unnecessary chainon() calls in c-parser.c
- From: gkeating at apple dot com (Geoffrey Keating)
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 3 Jun 2005 17:05:37 -0700 (PDT)
- Subject: Avoid unnecessary chainon() calls in c-parser.c
Originally, the YACC C parser had to use chainon in lots of places
because it couldn't keep any state around (like the end of the list).
Happily, those days are gone! Here are two places where chainon() is
used with a list that could be large; not generally very large, but
even a 10-element list gets built substantially slower when using
chainon compared to just appending with the last element known.
Bootstrapped & tested on powerpc-darwin8.
--
- Geoffrey Keating <geoffk@apple.com>
===File ~/patches/gcc-c-nochainonfuncdecl.patch=============
2005-06-03 Geoffrey Keating <geoffk@apple.com>
* c-parser.c (c_parser_parms_declarator): Don't use chainon().
(c_parser_expr_list): Don't use chainon().
Index: c-parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-parser.c,v
retrieving revision 2.15
diff -u -p -u -p -r2.15 c-parser.c
--- c-parser.c 26 May 2005 18:14:38 -0000 2.15
+++ c-parser.c 3 Jun 2005 23:44:40 -0000
@@ -2355,12 +2355,13 @@ c_parser_parms_declarator (c_parser *par
&& c_parser_next_token_is (parser, CPP_NAME)
&& c_parser_peek_token (parser)->id_kind == C_ID_ID)
{
- tree list = NULL_TREE;
+ tree list = NULL_TREE, *nextp = &list;
while (c_parser_next_token_is (parser, CPP_NAME)
&& c_parser_peek_token (parser)->id_kind == C_ID_ID)
{
- list = chainon (list, build_tree_list (NULL_TREE,
- c_parser_peek_token (parser)->value));
+ *nextp = build_tree_list (NULL_TREE,
+ c_parser_peek_token (parser)->value);
+ nextp = & TREE_CHAIN (*nextp);
c_parser_consume_token (parser);
if (c_parser_next_token_is_not (parser, CPP_COMMA))
break;
@@ -5294,14 +5295,14 @@ static tree
c_parser_expr_list (c_parser *parser)
{
struct c_expr expr;
- tree ret;
+ tree ret, cur;
expr = c_parser_expr_no_commas (parser, NULL);
- ret = build_tree_list (NULL_TREE, expr.value);
+ ret = cur = build_tree_list (NULL_TREE, expr.value);
while (c_parser_next_token_is (parser, CPP_COMMA))
{
c_parser_consume_token (parser);
expr = c_parser_expr_no_commas (parser, NULL);
- ret = chainon (ret, build_tree_list (NULL_TREE, expr.value));
+ cur = TREE_CHAIN (cur) = build_tree_list (NULL_TREE, expr.value);
}
return ret;
}
============================================================