public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/3] misc: use _fitoa_word to implement __fd_to_filename.
@ 2021-05-04  1:51 Érico Nogueira
  2021-05-04  1:51 ` [PATCH 2/3] linux: use fd_to_filename instead of _fitoa_word in ttyname_r Érico Nogueira
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Érico Nogueira @ 2021-05-04  1:51 UTC (permalink / raw)
  To: libc-alpha; +Cc: Érico Nogueira

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(-)

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


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

end of thread, other threads:[~2021-05-07 19:21 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-04  1:51 [PATCH 1/3] misc: use _fitoa_word to implement __fd_to_filename Érico Nogueira
2021-05-04  1:51 ` [PATCH 2/3] linux: use fd_to_filename instead of _fitoa_word in ttyname_r Érico Nogueira
2021-05-04 13:18   ` Adhemerval Zanella
2021-05-04  1:51 ` [PATCH 3/3] linux: implement ttyname as a wrapper around ttyname_r Érico Nogueira
2021-05-04 16:37   ` Adhemerval Zanella
2021-05-04 16:43     ` Adhemerval Zanella
2021-05-07 17:21       ` Adhemerval Zanella
2021-05-07 19:20         ` Érico Nogueira
2021-05-04 13:18 ` [PATCH 1/3] misc: use _fitoa_word to implement __fd_to_filename Adhemerval Zanella

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