]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
misc: use _fitoa_word to implement __fd_to_filename.
authorÉrico Nogueira <ericonr@disroot.org>
Tue, 4 May 2021 01:51:50 +0000 (22:51 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 7 May 2021 16:54:36 +0000 (13:54 -0300)
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.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
misc/fd_to_filename.c

index 86a1a1acc29ae6f72cbd6189b433f893e6cf3cba..20c201490376e3a1ca98ea87494398653c4e5abb 100644 (file)
@@ -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;
 }