From f3c9160cc5d4c1b7db900906c390ff68edf49e71 Mon Sep 17 00:00:00 2001 From: Stefan Schippers Date: Wed, 11 Nov 2020 19:01:22 +0100 Subject: [PATCH] keep frequently allocated memory chunks cached in get_tok_value() for better performance --- src/token.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/token.c b/src/token.c index ba58e66d..ec49d276 100644 --- a/src/token.c +++ b/src/token.c @@ -466,8 +466,8 @@ const char *get_tok_value(const char *s,const char *tok, int with_quotes) { static char *result=NULL; static char *token=NULL; - int size=0; - int sizetok=0; + static int size=0; + static int sizetok=0; register int c, space; register int token_pos=0, value_pos=0; int quote=0, state=TOK_BEGIN; @@ -477,14 +477,17 @@ const char *get_tok_value(const char *s,const char *tok, int with_quotes) if(s==NULL) { my_free(976, &result); my_free(977, &token); + size = sizetok = 0; get_tok_value_size = get_tok_size = 0; return ""; } get_tok_value_size = get_tok_size = 0; dbg(2, "get_tok_value(): looking for <%s> in <%s>\n",tok,s); - sizetok = size = CADCHUNKALLOC; - my_realloc(454, &result, size); - my_realloc(457, &token, sizetok); + if( size == 0 ) { + sizetok = size = CADCHUNKALLOC; + my_realloc(454, &result, size); + my_realloc(457, &token, sizetok); + } while(1) { c=*s++; space=SPACE(c) ;