From 9d46b25dedf5259f7a20dd2e8e8a6b738687babf Mon Sep 17 00:00:00 2001 From: Pádraig Brady Date: Wed, 25 Jan 2012 19:49:50 +0000 Subject: realpath: avoid the use of printf This was seen to give an 11% performance improvement. * src/realpath.c (relpath): Avoid using printf. (process_path): Likewise. --- src/realpath.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/realpath.c b/src/realpath.c index b03f37505..2dc5e111b 100644 --- a/src/realpath.c +++ b/src/realpath.c @@ -181,26 +181,27 @@ relpath (const char *can_fname) to a common directory. Then output the remainder of fname. */ if (*relto_suffix) { - printf ("%s", ".."); + fputs ("..", stdout); for (; *relto_suffix; ++relto_suffix) { if (*relto_suffix == '/') - printf ("%s", "/.."); + fputs ("/..", stdout); } if (*fname_suffix) - printf ("/%s", fname_suffix); + { + putchar ('/'); + fputs (fname_suffix, stdout); + } } else { if (*fname_suffix) - printf ("%s", fname_suffix); + fputs (fname_suffix, stdout); else - printf ("%c", '.'); + putchar ('.'); } - putchar (use_nuls ? '\0' : '\n'); - return true; } @@ -228,7 +229,9 @@ process_path (const char *fname, int can_mode) } if (!relpath (can_fname)) - printf ("%s%c", can_fname, (use_nuls ? '\0' : '\n')); + fputs (can_fname, stdout); + + putchar (use_nuls ? '\0' : '\n'); free (can_fname); -- cgit v1.2.3-70-g09d2