summaryrefslogtreecommitdiff
path: root/implicit.c
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2005-04-13 03:16:33 +0000
committerPaul Smith <psmith@gnu.org>2005-04-13 03:16:33 +0000
commit49ee105c685cb84bc3057e8b7666fc0cc7090047 (patch)
tree178eec81c5e39f56db9ca4b513376b3e1c5d35bf /implicit.c
parent3daf8df6ee835b9edcc068af33ae97910bb8d934 (diff)
downloadgunmake-49ee105c685cb84bc3057e8b7666fc0cc7090047.tar.gz
Fix performance degradation introduced by the second expansion feature.
I did this by adding intelligence into the algorithm such that the second expansion was only actually performed when the prerequisite list contained at least one "$", so we knew it is actually needed. Without this we were using up a LOT more memory, since every single target (even ones never used by make) had their file variables initialized. This also used a lot more CPU, since we needed to create and populate a new variable hash table for every target. There is one issue remaining with this feature: it leaks memory. In pattern_search() we now initialize the file variables for every pattern target, which allocates a hash table, etc. However, sometimes we recursively invoke pattern_search() (for intermediate files) with an automatic variable (alloca() I believe) as the file. When that function returns, obviously, the file variable hash memory is lost.
Diffstat (limited to 'implicit.c')
-rw-r--r--implicit.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/implicit.c b/implicit.c
index 338a29f..67f0559 100644
--- a/implicit.c
+++ b/implicit.c
@@ -509,19 +509,19 @@ pattern_search (struct file *file, int archive,
break; /* No more words */
/* If the dependency name has %, substitute the stem.
- Watch out, we are going to do something very smart
- here. If we just replace % with the stem value,
- later, when we do the second expansion, we will
- re-expand this stem value once again. This is not
- good especially if you have certain characters in
- your setm (like $).
+ Watch out, we are going to do something tricky here. If
+ we just replace % with the stem value, later, when we do
+ the second expansion, we will re-expand this stem value
+ once again. This is not good especially if you have
+ certain characters in your setm (like $).
- Instead, we will replace % with $* and allow the
- second expansion to take care of it for us. This
- way (since $* is a simple variable) there won't
- be additional re-expansion of the stem.*/
+ Instead, we will replace % with $* and allow the second
+ expansion to take care of it for us. This way (since $*
+ is a simple variable) there won't be additional
+ re-expansion of the stem. */
- for (p2 = p; p2 < p + len && *p2 != '%'; ++p2);
+ for (p2 = p; p2 < p + len && *p2 != '%'; ++p2)
+ ;
if (p2 < p + len)
{
@@ -836,6 +836,7 @@ pattern_search (struct file *file, int archive,
dep = (struct dep *) xmalloc (sizeof (struct dep));
dep->ignore_mtime = d->ignore_mtime;
+ dep->need_2nd_expansion = 0;
s = d->name; /* Hijacking the name. */
d->name = 0;
if (recursions == 0)
@@ -908,6 +909,7 @@ pattern_search (struct file *file, int archive,
struct dep *new = (struct dep *) xmalloc (sizeof (struct dep));
/* GKM FIMXE: handle '|' here too */
new->ignore_mtime = 0;
+ new->need_2nd_expansion = 0;
new->name = p = (char *) xmalloc (rule->lens[i] + fullstemlen + 1);
bcopy (rule->targets[i], p,
rule->suffixes[i] - rule->targets[i] - 1);