Bug 808245, Part 4/6 - Compile RegExpShared at execution time. r=dvander

This commit is contained in:
Sean Stangl 2012-12-12 17:23:04 -08:00
parent 227fa29d29
commit 123bfa85ad

View File

@ -469,7 +469,9 @@ RegExpRunStatus
RegExpShared::execute(JSContext *cx, StableCharPtr chars, size_t length, size_t *lastIndex, RegExpShared::execute(JSContext *cx, StableCharPtr chars, size_t length, size_t *lastIndex,
MatchPairs **output) MatchPairs **output)
{ {
JS_ASSERT(isCompiled()); /* Compile the code at point-of-use. */
if (!compileIfNecessary(cx))
return RegExpRunStatus_Error;
const size_t origLength = length; const size_t origLength = length;
size_t backingPairCount = pairCount() * 2; size_t backingPairCount = pairCount() * 2;
@ -574,26 +576,20 @@ RegExpCompartment::get(JSContext *cx, JSAtom *source, RegExpFlag flags, RegExpGu
if (!shared) if (!shared)
return false; return false;
if (!shared->compile(cx)) /* Add to RegExpShared sharing hashmap. */
return false; if (!map_.add(p, key, shared)) {
/* Re-lookup in case there was a GC. */
if (!map_.relookupOrAdd(p, key, shared)) {
js_ReportOutOfMemory(cx); js_ReportOutOfMemory(cx);
return false; return false;
} }
/* Add to list of all RegExpShared objects in this RegExpCompartment. */
if (!inUse_.put(shared)) { if (!inUse_.put(shared)) {
map_.remove(key); map_.remove(key);
js_ReportOutOfMemory(cx); js_ReportOutOfMemory(cx);
return false; return false;
} }
/* /* Since error deletes |shared|, only guard |shared| on success. */
* Since 'error' deletes 'shared', only guard 'shared' on success. This is
* safe since 'shared' cannot be deleted by GC until after the call to
* map_.relookupOrAdd() directly above.
*/
g->init(*shared.forget()); g->init(*shared.forget());
return true; return true;
} }