[Dctrl-tools-devel] [PATCH] lib/paragraph.c (para_parse_next): Unobvious performance changes

Antti-Juhani Kaijanaho ajk at debian.org
Wed Oct 31 22:18:12 UTC 2007


All of these changes have a measurable positive performance effect
on my laptop, and several similar changes not made here had
no measurable performance effect or had a measurable negative
performance effect.  The difference between what works and
what doesn't is completely unobvious to me.

Signed-off-by: Antti-Juhani Kaijanaho <ajk at debian.org>
---
 lib/paragraph.c |   17 ++++++-----------
 1 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/lib/paragraph.c b/lib/paragraph.c
index b5f5903..104f653 100644
--- a/lib/paragraph.c
+++ b/lib/paragraph.c
@@ -100,14 +100,13 @@ redo:
         int c;
 START:
         GETC;
-        switch (c) {
-        case -1:
+        if (__builtin_expect(c == -1,0)) {
                 pp->eof = true;
                 goto END;
-        case '\n':
+        } else if (c == '\n') {
                 para->start++;
                 goto START;
-        default:
+        } else {
                 field_start = --pos;
                 goto FIELD_NAME;
         }
@@ -182,15 +181,11 @@ BODY:
 
 BODY_NEWLINE:
         GETC;
-        switch (c) {
-        case -1:
-                //para->eof = true;
-                /* pass through */
-        case '\n':
+        if (c == -1 || c == '\n') {
                 goto END;
-        case ' ': case '\t':
+        } else if (c == ' ' || c == '\t') {
                 goto BODY_SKIPBLANKS;
-        default:
+        } else {
                 field_start = --pos;
 		goto FIELD_NAME;
         }
-- 
1.5.3.4




More information about the Dctrl-tools-devel mailing list