diff mbox series

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

Message ID 20201218063435.869976-1-siddhesh@sourceware.org
State New
Headers show
Series [COMMITTED] getenv: Move call to strlen to the branch it's used in. | expand

Commit Message

Siddhesh Poyarekar Dec. 18, 2020, 6:34 a.m. UTC
I have committed this to master after verifying that it does indeed
changed the generated assembly to a small extent and it is a useful
cleanup.

Siddhesh

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 mbox series

Patch

diff --git a/stdlib/getenv.c b/stdlib/getenv.c
index 57a8b6f013..b38b332ff8 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