Bug 834108 - avoid O(n^2) chunk-searching in LifoAlloc::ensureUnusedApproximate (r=dvander)

--HG--
extra : rebase_source : d3cb159978d10e6f74984d8556784081b2c940b9
This commit is contained in:
Luke Wagner 2013-01-24 14:36:17 -08:00
parent 374464c2bb
commit bebb8515b0
2 changed files with 6 additions and 12 deletions

View File

@ -140,12 +140,3 @@ LifoAlloc::transferUnusedFrom(LifoAlloc *other)
other->last = other->latest; other->last = other->latest;
} }
} }
bool
LifoAlloc::ensureUnusedApproximateSlow(size_t n)
{
// This relies on the behavior that releasing a chunk does not immediately free it.
LifoAllocScope scope(this);
return !!getOrCreateChunk(n);
}

View File

@ -182,8 +182,6 @@ class LifoAlloc
last = end; last = end;
} }
bool ensureUnusedApproximateSlow(size_t n);
public: public:
explicit LifoAlloc(size_t defaultChunkSize) { reset(defaultChunkSize); } explicit LifoAlloc(size_t defaultChunkSize) { reset(defaultChunkSize); }
@ -246,7 +244,12 @@ class LifoAlloc
return true; return true;
chunk = chunk->next(); chunk = chunk->next();
} }
return ensureUnusedApproximateSlow(n); BumpChunk *latestBefore = latest;
if (!getOrCreateChunk(n))
return false;
if (latestBefore)
latest = latestBefore;
return true;
} }
template <typename T> template <typename T>