[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 5/6] speedup parsing of functions
From: |
Paolo Bonzini |
Subject: |
[PATCH 5/6] speedup parsing of functions |
Date: |
Fri, 11 Aug 2017 13:44:32 +0200 |
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 a roughly 1% improvement on QEMU's noop build (from
11.23 to 11.1 seconds).
* function.c (find_next_argument, handle_function): Check
with STOP_SET before comparing against individual characters.
* main.c (initialize_stopchar_map): Initialize MAP_VARSEP
mappings in stopchar_map.
* makeint.h (MAP_VARSEP): 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 c70c155..55ff294 100644
--- a/function.c
+++ b/function.c
@@ -329,7 +329,10 @@ find_next_argument (char startparen, char endparen,
int count = 0;
for (; ptr < end; ++ptr)
- if (*ptr == startparen)
+ if (!STOP_SET (*ptr, MAP_VARSEP|MAP_COMMA))
+ continue;
+
+ else if (*ptr == startparen)
++count;
else if (*ptr == endparen)
@@ -2458,7 +2461,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_VARSEP|MAP_COMMA))
+ continue;
+ else if (*end == ',')
++nargs;
else if (*end == openparen)
++count;
diff --git a/main.c b/main.c
index 81ad3cd..f08fe7c 100644
--- a/main.c
+++ b/main.c
@@ -635,6 +635,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_VARSEP;
+ stopchar_map[(int)'{'] = MAP_VARSEP;
+ stopchar_map[(int)'}'] = MAP_VARSEP;
+ stopchar_map[(int)')'] = MAP_VARSEP;
stopchar_map[(int)'$'] = MAP_VARIABLE;
stopchar_map[(int)'-'] = MAP_USERFUNC;
diff --git a/makeint.h b/makeint.h
index d71c043..2adab63 100644
--- a/makeint.h
+++ b/makeint.h
@@ -397,6 +397,7 @@ extern int unixy_shell;
#define MAP_SEMI 0x0010
#define MAP_EQUALS 0x0020
#define MAP_COLON 0x0040
+#define MAP_VARSEP 0x0080
#define MAP_PIPE 0x0100
#define MAP_DOT 0x0200
#define MAP_COMMA 0x0400
--
2.13.3
- [PATCH v2 0/6] Miscellaneous speedup patches, Paolo Bonzini, 2017/08/11
- [PATCH 1/6] use Jenkins hash, Paolo Bonzini, 2017/08/11
- [PATCH 5/6] speedup parsing of functions,
Paolo Bonzini <=
- [PATCH 6/6] do not use STOP_SET for singleton sets, Paolo Bonzini, 2017/08/11
- [PATCH 3/6] use strchr/memmove in collapse_continuations, Paolo Bonzini, 2017/08/11
- [PATCH 2/6] use strchr for simple case of find_char_unquote, Paolo Bonzini, 2017/08/11
- [PATCH 4/6] remove MAP_PERCENT, Paolo Bonzini, 2017/08/11