Bug 670772 - JSCodeGenerator::upvarMap should use exactly as much space as it needs. (r=njn)

--HG--
extra : rebase_source : 40b9a070023da205817e275e936e8a1acbe38c2b
This commit is contained in:
Chris Leary 2011-07-13 16:05:41 -07:00
parent ea5644dbe3
commit 1ae6b9e3c0
3 changed files with 18 additions and 3 deletions

View File

@ -2315,8 +2315,19 @@ BindNameToSlot(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
size_t lexdepCount = cg->roLexdeps->count();
JS_ASSERT_IF(!upvarMap.empty(), lexdepCount == upvarMap.length());
if (upvarMap.empty() && !upvarMap.appendN(UpvarCookie(), lexdepCount))
return JS_FALSE;
if (upvarMap.empty()) {
/* Lazily initialize the upvar map with exactly the necessary capacity. */
if (lexdepCount <= upvarMap.sMaxInlineStorage) {
JS_ALWAYS_TRUE(upvarMap.growByUninitialized(lexdepCount));
} else {
void *buf = upvarMap.allocPolicy().malloc_(lexdepCount * sizeof(UpvarCookie));
if (!buf)
return JS_FALSE;
upvarMap.replaceRawBuffer(static_cast<UpvarCookie *>(buf), lexdepCount);
}
for (size_t i = 0; i < lexdepCount; ++i)
upvarMap[i] = UpvarCookie();
}
uintN slot = cookie.slot();
if (slot != UpvarCookie::CALLEE_SLOT && dn_kind != JSDefinition::ARG) {

View File

@ -196,7 +196,7 @@ class DefnOrHeader;
typedef InlineMap<JSAtom *, JSDefinition *, 24> AtomDefnMap;
typedef InlineMap<JSAtom *, jsatomid, 24> AtomIndexMap;
typedef InlineMap<JSAtom *, DefnOrHeader, 24> AtomDOHMap;
typedef Vector<UpvarCookie> UpvarCookies;
typedef Vector<UpvarCookie, 8> UpvarCookies;
} /* namespace js */

View File

@ -306,6 +306,10 @@ class Vector : private AllocPolicy
return *this;
}
AllocPolicy &allocPolicy() {
return *this;
}
enum { InlineLength = N };
size_t length() const {