This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Speed-up get_identifier("main") (take 3)
- From: Roger Sayle <roger at eyesopen dot com>
- To: Zack Weinberg <zack at codesourcery dot com>
- Cc: Jakub Jelinek <jakub at redhat dot com>, <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 7 Aug 2003 18:14:59 -0600 (MDT)
- Subject: [PATCH] Speed-up get_identifier("main") (take 3)
The following patch implements the suggestion of providing get_identifier
as a macro that checks whether the argument is a constant using
__builtin_constant_p, and if so calls get_identifier_with_length.
This version has the advantage of avoiding calls to strlen when the
string is known at compile-time, but without increasing code size
(inlining a call to strlen) when it isn't.
The following patch has been tested on i686-pc-linux-gnu with a full
"make bootstrap", all languages except treelang, and regression tested
with a top-level "make -k check" with no new failures.
Ok for mainline?
2003-08-07 Jakub Jelinek <jakub@redhat.com>
Roger Sayle <roger@eyesopen.com>
* tree.h (get_identifier): Define a macro form of get_identifier
that calls get_identifier_with_length when the string is constant.
* stringpool.c (get_identifier): Undefine the macro before giving
the function definition.
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.433
diff -c -3 -p -r1.433 tree.h
*** tree.h 5 Aug 2003 14:11:43 -0000 1.433
--- tree.h 7 Aug 2003 21:16:36 -0000
*************** extern tree make_tree_vec (int);
*** 2050,2055 ****
--- 2050,2063 ----
extern tree get_identifier (const char *);
+ #if GCC_VERSION >= 3000
+ #define get_identifier(str) \
+ (__builtin_constant_p (str) \
+ ? get_identifier_with_length ((str), (unsigned) strlen (str)) \
+ : get_identifier (str))
+ #endif
+
+
/* Identical to get_identifier, except that the length is assumed
known. */
Index: stringpool.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stringpool.c,v
retrieving revision 1.21
diff -c -3 -p -r1.21 stringpool.c
*** stringpool.c 6 Jul 2003 12:35:55 -0000 1.21
--- stringpool.c 7 Aug 2003 21:16:36 -0000
*************** ggc_alloc_string (const char *contents,
*** 95,100 ****
--- 95,102 ----
If an identifier with that name has previously been referred to,
the same node is returned this time. */
+ #undef get_identifier
+
tree
get_identifier (const char *text)
{
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833