summaryrefslogtreecommitdiff
path: root/function.c
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2003-03-25 00:15:25 +0000
committerPaul Smith <psmith@gnu.org>2003-03-25 00:15:25 +0000
commit955899ef770fc289febe3f186e4533e09baa7076 (patch)
tree4f3b49e3a7c2acba5cb614fdcf118814db022843 /function.c
parent4068c5e4a3eb0f47ec3cb4ee4fad5dd2edb9de6f (diff)
downloadgunmake-955899ef770fc289febe3f186e4533e09baa7076.tar.gz
Commit fix for bug #1418.
Upgrade to require autoconf 2.56. Fix a pathological performance hit substituting in large values with lots of words.
Diffstat (limited to 'function.c')
-rw-r--r--function.c19
1 files changed, 12 insertions, 7 deletions
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;