summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2012-01-25 19:49:50 +0000
committerPádraig Brady <P@draigBrady.com>2012-01-25 19:51:43 +0000
commit9d46b25dedf5259f7a20dd2e8e8a6b738687babf (patch)
tree97e9f23eb47b42a61715456026dee76f4f04faeb
parentc5cb2919395b9889efb8dde153bc83ed8fdf1ee6 (diff)
downloadcoreutils-9d46b25dedf5259f7a20dd2e8e8a6b738687babf.tar.xz
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.
-rw-r--r--src/realpath.c19
1 files 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);