bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 5/5] speedup parsing of functions


From: Paolo Bonzini
Subject: [PATCH 5/5] speedup parsing of functions
Date: Wed, 2 Nov 2016 17:24:18 +0100

Use the stopchar map to quickly jump over everything that is not an
open/close brace, an open/close parenthesis or a comma.  This provides
an 1.5% improvement on QEMU's noop build (from 13.2 seconds to 13).

* function.c (find_next_argument, handle_function): Ignore
characters quickly using the stopchar map.
* main.c (initialize_stopchar_map): Define MAP_PAREN.
* makeint.h (MAP_PAREN): New.
---
 function.c | 9 +++++++--
 main.c     | 4 ++++
 makeint.h  | 1 +
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/function.c b/function.c
index b7f0e56..aca0d71 100644
--- a/function.c
+++ b/function.c
@@ -328,7 +328,10 @@ find_next_argument (char startparen, char endparen,
   int count = 0;
 
   for (; ptr < end; ++ptr)
-    if (*ptr == startparen)
+    if (!STOP_SET (*ptr, MAP_PAREN|MAP_COMMA))
+      continue;
+
+    else if (*ptr == startparen)
       ++count;
 
     else if (*ptr == endparen)
@@ -2454,7 +2457,9 @@ handle_function (char **op, const char **stringp)
      count might be high, but it'll never be low.  */
 
   for (nargs=1, end=beg; *end != '\0'; ++end)
-    if (*end == ',')
+    if (!STOP_SET (*end, MAP_PAREN|MAP_COMMA))
+      continue;
+    else if (*end == ',')
       ++nargs;
     else if (*end == openparen)
       ++count;
diff --git a/main.c b/main.c
index 7f34199..1b1c16f 100644
--- a/main.c
+++ b/main.c
@@ -645,6 +645,10 @@ initialize_stopchar_map (void)
   stopchar_map[(int)'|'] = MAP_PIPE;
   stopchar_map[(int)'.'] = MAP_DOT | MAP_USERFUNC;
   stopchar_map[(int)','] = MAP_COMMA;
+  stopchar_map[(int)'('] = MAP_PAREN;
+  stopchar_map[(int)'{'] = MAP_PAREN;
+  stopchar_map[(int)'}'] = MAP_PAREN;
+  stopchar_map[(int)')'] = MAP_PAREN;
   stopchar_map[(int)'$'] = MAP_VARIABLE;
 
   stopchar_map[(int)'-'] = MAP_USERFUNC;
diff --git a/makeint.h b/makeint.h
index 15a69a8..aa24e4a 100644
--- a/makeint.h
+++ b/makeint.h
@@ -389,6 +389,7 @@ extern int unixy_shell;
 #define MAP_SEMI        0x0010
 #define MAP_EQUALS      0x0020
 #define MAP_COLON       0x0040
+#define MAP_PAREN       0x0080
 #define MAP_PIPE        0x0100
 #define MAP_DOT         0x0200
 #define MAP_COMMA       0x0400
-- 
2.7.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]