PATCH: reduce strlen() calls
Geoff Keating
geoffk@geoffk.org
Fri Jul 26 13:52:00 GMT 2002
Devang Patel <dpatel@apple.com> writes:
> On Friday, July 26, 2002, at 01:14 PM, Andreas Schwab wrote:
>
> > Devang Patel <dpatel@apple.com> writes:
> >
> > |> This simple patch reduces strlen() calls by using write_chars
> > (str, len)
> > |> instead of write_string (str).
> >
> > |> Index: cp/mangle.c
> > |>
> > ===================================================================
> > |> RCS file: /cvsroot/gcc/gcc/gcc/cp/mangle.c,v
> > |> retrieving revision 1.56
> > |> diff -c -3 -p -r1.56 mangle.c
> > |> *** cp/mangle.c 2 Jul 2002 03:19:22 -0000 1.56
> > |> --- cp/mangle.c 26 Jul 2002 19:21:23 -0000
> > |> *************** find_substitution (node)
> > |> *** 501,507 ****
> > |> && is_std_substitution (decl, SUBID_ALLOCATOR)
> > |> && !CLASSTYPE_USE_TEMPLATE (TREE_TYPE (decl)))
> > |> {
> > |> ! write_string ("Sa");
> > |> return 1;
> > |> }
> > |>
> > |> --- 501,507 ----
> > |> && is_std_substitution (decl, SUBID_ALLOCATOR)
> > |> && !CLASSTYPE_USE_TEMPLATE (TREE_TYPE (decl)))
> > |> {
> > |> ! write_chars ("Sa", 2);
> > |> return 1;
> > |> }
> > |>
> >
> > IMHO it would be more robust to use a macro that expands to
> > `write_chars
> > (str, strlen (str))' instead of using plain numbers.
>
> I think, that's what `write_string` macro is doing. But if a string
> size is
> fixed, why run strlen() to measure it?
GCC is supposed to evaluate strlen() of a constant string at compile
time, so it doesn't actually get called anyway.
--
- Geoffrey Keating <geoffk@geoffk.org> <geoffk@redhat.com>
More information about the Gcc-patches
mailing list