public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PATCH: reduce strlen() calls
@ 2002-07-26 13:14 Devang Patel
  2002-07-26 13:33 ` Andreas Schwab
  0 siblings, 1 reply; 9+ messages in thread
From: Devang Patel @ 2002-07-26 13:14 UTC (permalink / raw)
  To: gcc-patches

This simple patch reduces strlen() calls by using write_chars (str, len)
instead of write_string (str).

Bootstrapped and finished test suite check.

-Devang

2002-07-25 Devang Patel <dpatel@apple.com>
         * cp/mangle.c (find_substitution): Use write_chars () instead 
of write_string.
         (write_unscoped_name): Same.
         (write_unqualified_name): Same.
         (write_special_name_constructor): Same.
         (write_special_name_destructor): Same.
         (write_type): Same.
         (write_expression): Same.
         (mangle_special_for_type): Same.
         (mangle_ctor_vtbl_for_type): Same.
         (mangle_thunk): Same.
         (mangle_guard_variable): Same.
         (mangle_ref_init_variable): Same.



         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;
               }

         *************** find_substitution (node)
         *** 526,532 ****
                           && is_std_substitution_char (TREE_VEC_ELT 
(args, 2),
                                                        SUBID_ALLOCATOR))
                         {
         !                 write_string ("Ss");
                           return 1;
                         }
                     }
         --- 526,532 ----
                           && is_std_substitution_char (TREE_VEC_ELT 
(args, 2),
                                                        SUBID_ALLOCATOR))
                         {
         !                 write_chars ("Ss", 2);
                           return 1;
                         }
                     }
         *************** find_substitution (node)
         *** 534,540 ****
                 else
                 /* Substitute for the template name only if this isn't 
a type.  */
                 {
         !         write_string ("Sb");
                   return 1;
                 }
               }
         --- 534,540 ----
                 else
                 /* Substitute for the template name only if this isn't 
a type.  */
                 {
         !         write_chars ("Sb", 2);
                   return 1;
                 }
               }
         *************** find_substitution (node)
         *** 558,576 ****
                   tree name = DECL_NAME (CLASSTYPE_TI_TEMPLATE (type));
                  if (name == subst_identifiers[SUBID_BASIC_ISTREAM])
                     {
         !             write_string ("Si");
                       return 1;
                     }
                   /* Or basic_ostream?  */
                   else if (name == 
subst_identifiers[SUBID_BASIC_OSTREAM])
                     {
         !             write_string ("So");
                       return 1;
                     }
                   /* Or basic_iostream?  */
                   else if (name == 
subst_identifiers[SUBID_BASIC_IOSTREAM])
                     {
         !             write_string ("Sd");
                       return 1;
                     }
                 }
         --- 558,576 ----
                   tree name = DECL_NAME (CLASSTYPE_TI_TEMPLATE (type));
                   if (name == subst_identifiers[SUBID_BASIC_ISTREAM])
                     {
         !             write_chars ("Si", 2);
                       return 1;
                     }
                   /* Or basic_ostream?  */
                   else if (name == 
subst_identifiers[SUBID_BASIC_OSTREAM])
                     {
         !             write_chars ("So", 2);
                       return 1;
                     }
                   /* Or basic_iostream?  */
                   else if (name == 
subst_identifiers[SUBID_BASIC_IOSTREAM])
                     {
         !             write_chars ("Sd", 2);
                       return 1;
                     }
                 }
         *************** find_substitution (node)
         *** 579,585 ****
             /* Check for namespace std.  */
             if (decl && DECL_NAMESPACE_STD_P (decl))
               {
         !       write_string ("St");
                 return 1;
               }

         --- 579,585 ----
             /* Check for namespace std.  */
             if (decl && DECL_NAMESPACE_STD_P (decl))
               {
         !       write_chars ("St", 2);
                 return 1;
               }

         *************** write_mangled_name (decl)
         *** 625,631 ****
             else
               /* C++ name; needs to be mangled.  */
               {
         !       write_string ("_Z");
                 write_encoding (decl);
               }
           }
         --- 625,631 ----
             else
               /* C++ name; needs to be mangled.  */
               {
         !       write_chars ("_Z", 2);
                 write_encoding (decl);
               }
           }
         *************** write_unscoped_name (decl)
         *** 775,781 ****
             /* Is DECL in ::std?  */
             if (DECL_NAMESPACE_STD_P (context))
               {
         !       write_string ("St");
                 write_unqualified_name (decl);
               }
             /* If not, it should be either in the global namespace, or 
directly
         --- 775,781 ----
             /* Is DECL in ::std?  */
             if (DECL_NAMESPACE_STD_P (context))
               {
         !       write_chars ("St", 2);
                 write_unqualified_name (decl);
               }
             /* If not, it should be either in the global namespace, or 
directly
         *************** write_unqualified_name (decl)
         *** 997,1003 ****
                 }
                 else
                 type = TREE_TYPE (DECL_NAME (decl));
         !       write_string ("cv");
                 write_type (type);
               }
             else if (DECL_OVERLOADED_OPERATOR_P (decl))
         --- 997,1003 ----
                 }
                 else
                 type = TREE_TYPE (DECL_NAME (decl));
         !       write_chars ("cv", 2);
                 write_type (type);
               }
             else if (DECL_OVERLOADED_OPERATOR_P (decl))
         *************** write_special_name_constructor (ctor)
         *** 1196,1204 ****
                  old-style destructor, we still have to consider 
entities
                  (like static variables) nested inside it.  */
                 || DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (ctor))
     !     write_string ("C1");
             else if (DECL_BASE_CONSTRUCTOR_P (ctor))
         !     write_string ("C2");
             else
               abort ();
           }
         --- 1196,1204 ----
                  old-style destructor, we still have to consider 
entities
                  (like static variables) nested inside it.  */
                 || DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (ctor))
         !     write_chars ("C1", 2);
             else if (DECL_BASE_CONSTRUCTOR_P (ctor))
         !     write_chars ("C2", 2);
             else
               abort ();
           }
         *************** write_special_name_destructor (dtor)
         *** 1219,1233 ****
                tree dtor;
           {
             if (DECL_DELETING_DESTRUCTOR_P (dtor))
         !     write_string ("D0");
             else if (DECL_COMPLETE_DESTRUCTOR_P (dtor)
                    /* Even though we don't ever emit a definition of the
                       old-style destructor, we still have to consider 
entities
                     (like static variables) nested inside it.  */
                    || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (dtor))
         !     write_string ("D1");
             else if (DECL_BASE_DESTRUCTOR_P (dtor))
         !     write_string ("D2");
             else
               abort ();
           }
         --- 1219,1233 ----
                tree dtor;
           {
             if (DECL_DELETING_DESTRUCTOR_P (dtor))
         !     write_chars ("D0", 2);
             else if (DECL_COMPLETE_DESTRUCTOR_P (dtor)
                    /* Even though we don't ever emit a definition of the
                       old-style destructor, we still have to consider 
entities
                       (like static variables) nested inside it.  */
                    || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (dtor))
         !     write_chars ("D1", 2);
             else if (DECL_BASE_DESTRUCTOR_P (dtor))
         !     write_chars ("D2", 2);
             else
               abort ();
           }
         *************** write_type (type)
         *** 1456,1462 ****
                   break;

                 case VECTOR_TYPE:
         !         write_string ("U8__vector");
                   write_type (TREE_TYPE (type));
                   break;

         --- 1456,1462 ----
                   break;

                 case VECTOR_TYPE:
         !         write_chars ("U8__vector", 10);
                   write_type (TREE_TYPE (type));
                   break;

         *************** write_expression (expr)
         *** 1837,1843 ****
             else if (TREE_CODE (expr) == SIZEOF_EXPR
                    && TYPE_P (TREE_OPERAND (expr, 0)))
               {
         !       write_string ("st");
                 write_type (TREE_OPERAND (expr, 0));
               }
             else
         --- 1837,1843 ----
             else if (TREE_CODE (expr) == SIZEOF_EXPR
                    && TYPE_P (TREE_OPERAND (expr, 0)))
               {
         !       write_chars ("st", 2);
               write_type (TREE_OPERAND (expr, 0));
               }
             else
         *************** mangle_special_for_type (type, code)
         *** 2310,2316 ****
             start_mangling ();

             /* Start the mangling.  */
         !   write_string ("_Z");
             write_string (code);

             /* Add the type.  */
         --- 2310,2316 ----
             start_mangling ();

             /* Start the mangling.  */
         !   write_chars ("_Z", 2);
             write_string (code);

             /* Add the type.  */
         *************** mangle_ctor_vtbl_for_type (type, binfo)
         *** 2384,2391 ****

             start_mangling ();

         !   write_string ("_Z");
         !   write_string ("TC");
             write_type (type);
             write_integer_cst (BINFO_OFFSET (binfo));
             write_char ('_');
         --- 2384,2391 ----

             start_mangling ();

         !   write_chars ("_Z", 2);
         !   write_chars ("TC", 2);
             write_type (type);
             write_integer_cst (BINFO_OFFSET (binfo));
             write_char ('_');
         *************** mangle_thunk (fn_decl, offset, vcall_off
         *** 2417,2423 ****

             start_mangling ();

         !   write_string ("_Z");
             /* The <special-name> for virtual thunks is Tv, for 
non-virtual
                thunks Th.  */
             write_char ('T');
         --- 2417,2423 ----

             start_mangling ();

         !   write_chars ("_Z", 2);
             /* The <special-name> for virtual thunks is Tv, for 
non-virtual
                thunks Th.  */
             write_char ('T');
         *************** mangle_guard_variable (variable)
         *** 2494,2500 ****
                tree variable;
           {
             start_mangling ();
         !   write_string ("_ZGV");
             if (strncmp (IDENTIFIER_POINTER (DECL_NAME (variable)), 
"_ZGR", 4) == 0)
               /* The name of a guard variable for a reference temporary 
should refer
                  to the reference, not the temporary.  */
         --- 2494,2500 ----
                tree variable;
           {
             start_mangling ();
         !   write_chars ("_ZGV", 4);
             if (strncmp (IDENTIFIER_POINTER (DECL_NAME (variable)), 
"_ZGR", 4) == 0)
               /* The name of a guard variable for a reference temporary 
should refer
                  to the reference, not the temporary.  */
         *************** mangle_ref_init_variable (variable)
         *** 2513,2519 ****
                tree variable;
           {
             start_mangling ();
         !   write_string ("_ZGR");
             write_name (variable, /*ignore_local_scope=*/0);
             return get_identifier (finish_mangling ());
           }
         --- 2513,2519 ----
                tree variable;
           {
             start_mangling ();
         !   write_chars ("_ZGR", 4);
             write_name (variable, /*ignore_local_scope=*/0);
             return get_identifier (finish_mangling ());
           }

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: PATCH: reduce strlen() calls
  2002-07-26 13:14 PATCH: reduce strlen() calls Devang Patel
@ 2002-07-26 13:33 ` Andreas Schwab
  2002-07-26 13:36   ` Devang Patel
  0 siblings, 1 reply; 9+ messages in thread
From: Andreas Schwab @ 2002-07-26 13:33 UTC (permalink / raw)
  To: Devang Patel; +Cc: gcc-patches

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.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: PATCH: reduce strlen() calls
  2002-07-26 13:33 ` Andreas Schwab
@ 2002-07-26 13:36   ` Devang Patel
  2002-07-26 13:47     ` Andrew Pinski
                       ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Devang Patel @ 2002-07-26 13:36 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: gcc-patches


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?

-Devang

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: PATCH: reduce strlen() calls
  2002-07-26 13:36   ` Devang Patel
@ 2002-07-26 13:47     ` Andrew Pinski
  2002-07-26 13:52     ` Geoff Keating
  2002-07-29  9:41     ` Mark Mitchell
  2 siblings, 0 replies; 9+ messages in thread
From: Andrew Pinski @ 2002-07-26 13:47 UTC (permalink / raw)
  To: Devang Patel; +Cc: Andreas Schwab, gcc-patches

Is it true that strlen(CONST_STRING) is optimized?

I think it is, and I just tried it on:
Reading specs from /usr/local/bin/../lib/gcc-lib/sparc-sun-
solaris2.8/3.0.4/specs
Configured with: ./configure --prefix=/usr/local/stow/gcc-3.0.4
Thread model: posix
gcc version 3.0.4

And it seems it is on even -O0.

Thanks,
Andrew Pinski

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: PATCH: reduce strlen() calls
  2002-07-26 13:36   ` Devang Patel
  2002-07-26 13:47     ` Andrew Pinski
@ 2002-07-26 13:52     ` Geoff Keating
  2002-07-26 14:07       ` Devang Patel
  2002-07-29  9:41     ` Mark Mitchell
  2 siblings, 1 reply; 9+ messages in thread
From: Geoff Keating @ 2002-07-26 13:52 UTC (permalink / raw)
  To: Devang Patel; +Cc: gcc-patches

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>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: PATCH: reduce strlen() calls
  2002-07-26 13:52     ` Geoff Keating
@ 2002-07-26 14:07       ` Devang Patel
  2002-07-26 14:12         ` Geoff Keating
  0 siblings, 1 reply; 9+ messages in thread
From: Devang Patel @ 2002-07-26 14:07 UTC (permalink / raw)
  To: Geoff Keating; +Cc: gcc-patches


On Friday, July 26, 2002, at 01:39  PM, Geoff Keating wrote:

>> 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.

Oh, OK. I did not know about it.
Where can I find code to do this in gcc sources?

So, it only effects compiler bootstrap. On the other side, we are the
ones who pay cost of bootstrap time.

Apart from this, is there any reason not to use fixed size number
for fixed strings?  May be I am missing something obvious?

Thank you,
-Devang

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: PATCH: reduce strlen() calls
  2002-07-26 14:07       ` Devang Patel
@ 2002-07-26 14:12         ` Geoff Keating
  2002-07-26 15:58           ` Devang Patel
  0 siblings, 1 reply; 9+ messages in thread
From: Geoff Keating @ 2002-07-26 14:12 UTC (permalink / raw)
  To: dpatel; +Cc: gcc-patches

> Date: Fri, 26 Jul 2002 13:52:53 -0700
> Cc: gcc-patches@gcc.gnu.org
> From: Devang Patel <dpatel@apple.com>
> X-OriginalArrivalTime: 26 Jul 2002 20:53:05.0682 (UTC) FILETIME=[70A59F20:01C234E6]
> 
> 
> On Friday, July 26, 2002, at 01:39  PM, Geoff Keating wrote:
> 
> >> 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.
> 
> Oh, OK. I did not know about it.
> Where can I find code to do this in gcc sources?

In expand_builtin_strlen in builtins.c.

> So, it only effects compiler bootstrap. On the other side, we are the
> ones who pay cost of bootstrap time.

I think you'll find that there is no perceptible impact on the time it
takes to bootstrap either way.

> Apart from this, is there any reason not to use fixed size number
> for fixed strings?  May be I am missing something obvious?

The obvious reason is that:

- The number might be wrong
- The number might start correct, but then someone might change the
  code and forget to update the number.

-- 
- Geoffrey Keating <geoffk@geoffk.org> <geoffk@redhat.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: PATCH: reduce strlen() calls
  2002-07-26 14:12         ` Geoff Keating
@ 2002-07-26 15:58           ` Devang Patel
  0 siblings, 0 replies; 9+ messages in thread
From: Devang Patel @ 2002-07-26 15:58 UTC (permalink / raw)
  To: Geoff Keating; +Cc: gcc-patches


On Friday, July 26, 2002, at 02:01  PM, Geoff Keating wrote:

>> Date: Fri, 26 Jul 2002 13:52:53 -0700
>> Cc: gcc-patches@gcc.gnu.org
>> From: Devang Patel <dpatel@apple.com>
>> X-OriginalArrivalTime: 26 Jul 2002 20:53:05.0682 (UTC) 
>> FILETIME=[70A59F20:01C234E6]
>>
>>
>> On Friday, July 26, 2002, at 01:39  PM, Geoff Keating wrote:
>>
>>>> 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.
>>
>> Oh, OK. I did not know about it.
>> Where can I find code to do this in gcc sources?
>
> In expand_builtin_strlen in builtins.c.

Thank you.

>> So, it only effects compiler bootstrap. On the other side, we are the
>> ones who pay cost of bootstrap time.
>
> I think you'll find that there is no perceptible impact on the time it
> takes to bootstrap either way.
>
>> Apart from this, is there any reason not to use fixed size number
>> for fixed strings?  May be I am missing something obvious?
>
> The obvious reason is that:
>
> - The number might be wrong
> - The number might start correct, but then someone might change the
>   code and forget to update the number.

I agree. I am revoking my patch.

Thanks,
-Devang

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: PATCH: reduce strlen() calls
  2002-07-26 13:36   ` Devang Patel
  2002-07-26 13:47     ` Andrew Pinski
  2002-07-26 13:52     ` Geoff Keating
@ 2002-07-29  9:41     ` Mark Mitchell
  2 siblings, 0 replies; 9+ messages in thread
From: Mark Mitchell @ 2002-07-29  9:41 UTC (permalink / raw)
  To: Devang Patel, Andreas Schwab; +Cc: gcc-patches

> I think, that's what `write_string` macro is doing. But if a string size
> is fixed, why run strlen() to measure it?

1. It makes it easy to get the right answer.

2. It makes the code more robust -- you do not have to remember to change
   the number.

3. It is not any slower; GCC will optimize away the call to strlen anyhow.

-- 
Mark Mitchell                mark@codesourcery.com
CodeSourcery, LLC            http://www.codesourcery.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2002-07-29 16:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-26 13:14 PATCH: reduce strlen() calls Devang Patel
2002-07-26 13:33 ` Andreas Schwab
2002-07-26 13:36   ` Devang Patel
2002-07-26 13:47     ` Andrew Pinski
2002-07-26 13:52     ` Geoff Keating
2002-07-26 14:07       ` Devang Patel
2002-07-26 14:12         ` Geoff Keating
2002-07-26 15:58           ` Devang Patel
2002-07-29  9:41     ` Mark Mitchell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).