Commit bb64d1c92fbbc2441772f2eb9b4527499955c04e

Authored by Joe Hershberger
Committed by Tom Rini
1 parent da83bcd7b3

Output strings from echo with puts where easy

Change echo to puts characters together where it knows about them
together.  This improves netconsole performance by greatly reducing
the number of packets that are sent.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

Showing 1 changed file with 21 additions and 7 deletions Side-by-side Diff

... ... @@ -30,17 +30,31 @@
30 30 int putnl = 1;
31 31  
32 32 for (i = 1; i < argc; i++) {
33   - char *p = argv[i], c;
  33 + char *p = argv[i];
  34 + char *nls; /* new-line suppression */
34 35  
35 36 if (i > 1)
36 37 putc(' ');
37   - while ((c = *p++) != '\0') {
38   - if (c == '\\' && *p == 'c') {
39   - putnl = 0;
40   - p++;
41   - } else {
42   - putc(c);
  38 +
  39 + nls = strstr(p, "\\c");
  40 + if (nls) {
  41 + char *prenls = p;
  42 +
  43 + putnl = 0;
  44 + /*
  45 + * be paranoid and guess that someone might
  46 + * say \c more than once
  47 + */
  48 + while (nls) {
  49 + *nls = '\0';
  50 + puts(prenls);
  51 + *nls = '\\';
  52 + prenls = nls + 2;
  53 + nls = strstr(prenls, "\\c");
43 54 }
  55 + puts(prenls);
  56 + } else {
  57 + puts(p);
44 58 }
45 59 }
46 60