svn commit: trunk/busybox/coreutils
vda at busybox.net
vda at busybox.net
Tue Apr 10 16:34:01 UTC 2007
Author: vda
Date: 2007-04-10 09:34:00 -0700 (Tue, 10 Apr 2007)
New Revision: 18383
Log:
echo: fix regression ("echo" with no arguments didn't print newline.
echo: use fputs if no options are given. Code growth ~15 bytes.
Old:
# time ./busybox find $bigdir -exec echo {} \; >/dev/null
real 0m2.038s
user 0m0.761s
sys 0m0.953s
New:
# time ./busybox find $bigdir -exec echo {} \; >/dev/null
real 0m1.781s
user 0m0.781s
sys 0m0.939s
For comparison: without NOFORK:
# time find $bigdir -exec echo {} \; >/dev/null
real 1m51.129s
user 0m38.442s
sys 1m3.350s
Modified:
trunk/busybox/coreutils/echo.c
Changeset:
Modified: trunk/busybox/coreutils/echo.c
===================================================================
--- trunk/busybox/coreutils/echo.c 2007-04-10 15:43:37 UTC (rev 18382)
+++ trunk/busybox/coreutils/echo.c 2007-04-10 16:34:00 UTC (rev 18383)
@@ -29,7 +29,10 @@
{
const char *arg;
#if !ENABLE_FEATURE_FANCY_ECHO
-#define eflag '\\'
+ enum {
+ eflag = '\\',
+ nflag = 1, /* 1 -- print '\n' */
+ };
++argv;
#else
const char *p;
@@ -39,7 +42,7 @@
while (1) {
arg = *++argv;
if (!arg)
- goto ret;
+ goto newline_ret;
if (*arg != '-')
break;
@@ -68,10 +71,13 @@
just_echo:
#endif
while (1) {
- /* arg is already = *argv and isn't NULL */
+ /* arg is already == *argv and isn't NULL */
int c;
- while ((c = *arg++)) {
+ if (!eflag) {
+ /* optimization for very common case */
+ fputs(arg, stdout);
+ } else while ((c = *arg++)) {
if (c == eflag) { /* Check for escape seq. */
if (*arg == 'c') {
/* '\c' means cancel newline and
@@ -101,13 +107,10 @@
putchar(' ');
}
-#ifdef CONFIG_FEATURE_FANCY_ECHO
+ newline_ret:
if (nflag) {
putchar('\n');
}
-#else
- putchar('\n');
-#endif
ret:
return fflush(stdout);
}
More information about the busybox-cvs
mailing list