From 7963580d72a358975133f86f01de2d2eab08ba38 Mon Sep 17 00:00:00 2001 From: xXx-caillou-xXx Date: Fri, 13 Jul 2018 10:36:50 +0200 Subject: Massively optimize how rules are handled This commit does a lot of things: - Use hashtables instead of lists to store the rules - Rules that can be applied at launch time won't be tried at runtime - Improve feedback when writing nonsensical rules - Make intensive use of `zend_string` instead of `char*`--- src/sp_config_utils.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/sp_config_utils.c') diff --git a/src/sp_config_utils.c b/src/sp_config_utils.c index 130f07e..d72561b 100644 --- a/src/sp_config_utils.c +++ b/src/sp_config_utils.c @@ -32,18 +32,18 @@ int parse_keywords(sp_config_functions *funcs, char *line) { return 0; } -char *get_param(size_t *consumed, char *restrict line, sp_type type, - const char *restrict keyword) { +zend_string *get_param(size_t *consumed, char *restrict line, sp_type type, + const char *restrict keyword) { enum { IN_ESCAPE, NONE } state = NONE; char *original_line = line; size_t j = 0; - char *ret = NULL; + zend_string *ret = NULL; if (NULL == line || '\0' == *line) { goto err; } - ret = pecalloc(sizeof(char), strlen(original_line) + 1, 1); + ret = zend_string_alloc(strlen(line) + 1, 1); /* The first char of a string is always '"', since they MUST be quoted. */ if ('"' == *line) { @@ -65,6 +65,11 @@ char *get_param(size_t *consumed, char *restrict line, sp_type type, 2. the SP_TOKEN_END_PARAM */ *consumed = i + 2; + // Make sure that the string we return is the right size, + // as it can be smaller than strlen(line) + ret = zend_string_truncate(ret, j, 1); + // truncate does not add a \0 + ZSTR_VAL(ret)[ZSTR_LEN(ret)] = 0; return ret; } else if (state == IN_ESCAPE) { break; // we're on an escped double quote @@ -82,7 +87,7 @@ char *get_param(size_t *consumed, char *restrict line, sp_type type, if (state == IN_ESCAPE) { state = NONE; } - ret[j++] = line[i]; + ZSTR_VAL(ret)[j++] = line[i]; } err: if (0 == j) { -- cgit v1.3