dmesg: more correct skipping of <N>; use faster putchar for most output
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 19 Oct 2010 21:08:33 +0000 (23:08 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 19 Oct 2010 21:08:33 +0000 (23:08 +0200)
function                                             old     new   delta
dmesg_main                                           246     291     +45

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
util-linux/dmesg.c

index 06a03d3fb76af17c29b101ca56a87de0bdd9feae..6e43a22f5605a047c2a34d0dc303a0f82e2b4203 100644 (file)
@@ -45,20 +45,25 @@ int dmesg_main(int argc UNUSED_PARAM, char **argv)
        if (len == 0)
                return EXIT_SUCCESS;
 
-       /* Skip <#> at the start of lines, and make sure we end with a newline */
 
        if (ENABLE_FEATURE_DMESG_PRETTY) {
                int last = '\n';
                int in = 0;
 
-               do {
-                       if (last == '\n' && buf[in] == '<')
+               /* Skip <#> at the start of lines */
+               while (1) {
+                       if (last == '\n' && buf[in] == '<') {
                                in += 3;
-                       else {
-                               last = buf[in++];
-                               bb_putchar(last);
+                               if (in >= len)
+                                       break;
                        }
-               } while (in < len);
+                       last = buf[in];
+                       putchar(last);
+                       in++;
+                       if (in >= len)
+                               break;
+               }
+               /* Make sure we end with a newline */
                if (last != '\n')
                        bb_putchar('\n');
        } else {