diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-10 16:34:00 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-10 16:34:00 +0000 |
commit | a9d7d24e1f524bb7528aa881265fe8f826023751 (patch) | |
tree | 4bc59ebc7d362ce5d9f4f733e7ba633be8534f72 | |
parent | 99912ca733dd960f5589227fd999c86e73c8e894 (diff) | |
download | busybox-w32-a9d7d24e1f524bb7528aa881265fe8f826023751.tar.gz busybox-w32-a9d7d24e1f524bb7528aa881265fe8f826023751.tar.bz2 busybox-w32-a9d7d24e1f524bb7528aa881265fe8f826023751.zip |
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
-rw-r--r-- | coreutils/echo.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/coreutils/echo.c b/coreutils/echo.c index 486245508..2ee5002ba 100644 --- a/coreutils/echo.c +++ b/coreutils/echo.c | |||
@@ -29,7 +29,10 @@ int bb_echo(char **argv) | |||
29 | { | 29 | { |
30 | const char *arg; | 30 | const char *arg; |
31 | #if !ENABLE_FEATURE_FANCY_ECHO | 31 | #if !ENABLE_FEATURE_FANCY_ECHO |
32 | #define eflag '\\' | 32 | enum { |
33 | eflag = '\\', | ||
34 | nflag = 1, /* 1 -- print '\n' */ | ||
35 | }; | ||
33 | ++argv; | 36 | ++argv; |
34 | #else | 37 | #else |
35 | const char *p; | 38 | const char *p; |
@@ -39,7 +42,7 @@ int bb_echo(char **argv) | |||
39 | while (1) { | 42 | while (1) { |
40 | arg = *++argv; | 43 | arg = *++argv; |
41 | if (!arg) | 44 | if (!arg) |
42 | goto ret; | 45 | goto newline_ret; |
43 | if (*arg != '-') | 46 | if (*arg != '-') |
44 | break; | 47 | break; |
45 | 48 | ||
@@ -68,10 +71,13 @@ int bb_echo(char **argv) | |||
68 | just_echo: | 71 | just_echo: |
69 | #endif | 72 | #endif |
70 | while (1) { | 73 | while (1) { |
71 | /* arg is already = *argv and isn't NULL */ | 74 | /* arg is already == *argv and isn't NULL */ |
72 | int c; | 75 | int c; |
73 | 76 | ||
74 | while ((c = *arg++)) { | 77 | if (!eflag) { |
78 | /* optimization for very common case */ | ||
79 | fputs(arg, stdout); | ||
80 | } else while ((c = *arg++)) { | ||
75 | if (c == eflag) { /* Check for escape seq. */ | 81 | if (c == eflag) { /* Check for escape seq. */ |
76 | if (*arg == 'c') { | 82 | if (*arg == 'c') { |
77 | /* '\c' means cancel newline and | 83 | /* '\c' means cancel newline and |
@@ -101,13 +107,10 @@ int bb_echo(char **argv) | |||
101 | putchar(' '); | 107 | putchar(' '); |
102 | } | 108 | } |
103 | 109 | ||
104 | #ifdef CONFIG_FEATURE_FANCY_ECHO | 110 | newline_ret: |
105 | if (nflag) { | 111 | if (nflag) { |
106 | putchar('\n'); | 112 | putchar('\n'); |
107 | } | 113 | } |
108 | #else | ||
109 | putchar('\n'); | ||
110 | #endif | ||
111 | ret: | 114 | ret: |
112 | return fflush(stdout); | 115 | return fflush(stdout); |
113 | } | 116 | } |