From 955899ef770fc289febe3f186e4533e09baa7076 Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Tue, 25 Mar 2003 00:15:25 +0000 Subject: Commit fix for bug #1418. Upgrade to require autoconf 2.56. Fix a pathological performance hit substituting in large values with lots of words. --- function.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'function.c') diff --git a/function.c b/function.c index 361e3a8..08a4d56 100644 --- a/function.c +++ b/function.c @@ -80,13 +80,14 @@ subst_expand (char *o, char *text, char *subst, char *replace, unsigned int slen, unsigned int rlen, int by_word, int suffix_only) { - register char *t = text; - register char *p; + char *t = text; + unsigned int tlen = strlen (text); + char *p; if (slen == 0 && !by_word && !suffix_only) { /* The first occurrence of "" in any string is its end. */ - o = variable_buffer_output (o, t, strlen (t)); + o = variable_buffer_output (o, t, tlen); if (rlen > 0) o = variable_buffer_output (o, replace, rlen); return o; @@ -100,11 +101,11 @@ subst_expand (char *o, char *text, char *subst, char *replace, p = end_of_token (next_token (t)); else { - p = sindex (t, 0, subst, slen); + p = sindex (t, tlen, subst, slen); if (p == 0) { /* No more matches. Output everything left on the end. */ - o = variable_buffer_output (o, t, strlen (t)); + o = variable_buffer_output (o, t, tlen); return o; } } @@ -127,8 +128,12 @@ subst_expand (char *o, char *text, char *subst, char *replace, /* Output the replacement string. */ o = variable_buffer_output (o, replace, rlen); - /* Advance T past the string to be replaced. */ - t = p + slen; + /* Advance T past the string to be replaced; adjust tlen. */ + { + char *nt = p + slen; + tlen -= nt - t; + t = nt; + } } while (*t != '\0'); return o; -- cgit v1.2.3