This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] getenv: Move call to strlen to the branch it's used in.


* Lode Willems:

> The len variable is only used in the else branch.
> We don't need the call to strlen if the name is 0 or 1 characters long.
>
> 2019-10-02  Lode Willems  <Lode.Willems@UGent.be>
>
> 	* tdlib/getenv.c: Move the call to strlen into the branch it's used.
>
> diff --git a/stdlib/getenv.c b/stdlib/getenv.c
> index 6be97b2a54..aa5e69d0b0 100644
> --- a/stdlib/getenv.c
> +++ b/stdlib/getenv.c
> @@ -32,7 +32,6 @@
>  char *
>  getenv (const char *name)
>  {
> -  size_t len = strlen (name);
>    char **ep;
>    uint16_t name_start;
>  
> @@ -63,6 +62,7 @@ getenv (const char *name)
>      }
>    else
>      {
> +      size_t len = strlen (name);
>  #if _STRING_ARCH_unaligned
>        name_start = *(const uint16_t *) name;
>  #else

Thanks for the patch.  Is there any particular reason for making the
change?  I don't think it will alter the generated machine code.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]