diff mbox series

[1/3] misc: use _fitoa_word to implement __fd_to_filename.

Message ID 20210504015152.31064-1-ericonr@disroot.org
State Committed
Commit 330001202ada53dcf3de81f95edc2616f8d75c68
Headers show
Series [1/3] misc: use _fitoa_word to implement __fd_to_filename. | expand

Commit Message

√Črico Nogueira May 4, 2021, 1:51 a.m. UTC
In a default build for x86_64, size decreased by 24 bytes:
1883294 to 1883270.

Aditionally, avoids repeating the number printing logic in multiple
places.
---
 misc/fd_to_filename.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

Adhemerval Zanella May 4, 2021, 1:18 p.m. UTC | #1
On 03/05/2021 22:51, √Črico Nogueira via Libc-alpha wrote:
> In a default build for x86_64, size decreased by 24 bytes:
> 1883294 to 1883270.
> 
> Aditionally, avoids repeating the number printing logic in multiple
> places.


LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>


> ---
>  misc/fd_to_filename.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/misc/fd_to_filename.c b/misc/fd_to_filename.c
> index 86a1a1acc2..20c2014903 100644
> --- a/misc/fd_to_filename.c
> +++ b/misc/fd_to_filename.c
> @@ -20,6 +20,7 @@
>  
>  #include <assert.h>
>  #include <string.h>
> +#include <_itoa.h>
>  
>  char *
>  __fd_to_filename (int descriptor, struct fd_to_filename *storage)
> @@ -28,11 +29,7 @@ __fd_to_filename (int descriptor, struct fd_to_filename *storage)
>  
>    char *p = mempcpy (storage->buffer, FD_TO_FILENAME_PREFIX,
>                       strlen (FD_TO_FILENAME_PREFIX));
> +  *_fitoa_word (descriptor, p, 10, 0) = '\0';
>  
> -  for (int d = descriptor; p++, (d /= 10) != 0; )
> -    continue;
> -  *p = '\0';
> -  for (int d = descriptor; *--p = '0' + d % 10, (d /= 10) != 0; )
> -    continue;
>    return storage->buffer;
>  }
>
diff mbox series

Patch

diff --git a/misc/fd_to_filename.c b/misc/fd_to_filename.c
index 86a1a1acc2..20c2014903 100644
--- a/misc/fd_to_filename.c
+++ b/misc/fd_to_filename.c
@@ -20,6 +20,7 @@ 
 
 #include <assert.h>
 #include <string.h>
+#include <_itoa.h>
 
 char *
 __fd_to_filename (int descriptor, struct fd_to_filename *storage)
@@ -28,11 +29,7 @@  __fd_to_filename (int descriptor, struct fd_to_filename *storage)
 
   char *p = mempcpy (storage->buffer, FD_TO_FILENAME_PREFIX,
                      strlen (FD_TO_FILENAME_PREFIX));
+  *_fitoa_word (descriptor, p, 10, 0) = '\0';
 
-  for (int d = descriptor; p++, (d /= 10) != 0; )
-    continue;
-  *p = '\0';
-  for (int d = descriptor; *--p = '0' + d % 10, (d /= 10) != 0; )
-    continue;
   return storage->buffer;
 }