Bug 808245, Part 4/6 - Compile RegExpShared at execution time. r=dvander
authorSean Stangl <sstangl@mozilla.com>
Wed, 12 Dec 2012 17:23:04 -0800
changeset 125219 d229008d60acd336e99efc1b44d3f774634fa939
parent 125218 ea7d93401f966c3cb68fe07d8b989514747f3a1a
child 125220 7711a36c27717f84038edbfc8a2f3e2788dc46d3
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdvander
bugs808245
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 808245, Part 4/6 - Compile RegExpShared at execution time. r=dvander
js/src/vm/RegExpObject.cpp
--- a/js/src/vm/RegExpObject.cpp
+++ b/js/src/vm/RegExpObject.cpp
@@ -464,17 +464,19 @@ RegExpShared::compileIfNecessary(JSConte
         return true;
     return compile(cx);
 }
 
 RegExpRunStatus
 RegExpShared::execute(JSContext *cx, StableCharPtr chars, size_t length, size_t *lastIndex,
                       MatchPairs **output)
 {
-    JS_ASSERT(isCompiled());
+    /* Compile the code at point-of-use. */
+    if (!compileIfNecessary(cx))
+        return RegExpRunStatus_Error;
 
     const size_t origLength = length;
     size_t backingPairCount = pairCount() * 2;
 
     LifoAlloc &alloc = cx->tempLifoAlloc();
     MatchPairs *matchPairs = MatchPairs::create(alloc, pairCount(), backingPairCount);
     if (!matchPairs)
         return RegExpRunStatus_Error;
@@ -569,36 +571,30 @@ RegExpCompartment::get(JSContext *cx, JS
         g->init(*p->value);
         return true;
     }
 
     ScopedDeletePtr<RegExpShared> shared(cx->new_<RegExpShared>(cx->runtime, source, flags));
     if (!shared)
         return false;
 
-    if (!shared->compile(cx))
-        return false;
-
-    /* Re-lookup in case there was a GC. */
-    if (!map_.relookupOrAdd(p, key, shared)) {
+    /* Add to RegExpShared sharing hashmap. */
+    if (!map_.add(p, key, shared)) {
         js_ReportOutOfMemory(cx);
         return false;
     }
 
+    /* Add to list of all RegExpShared objects in this RegExpCompartment. */
     if (!inUse_.put(shared)) {
         map_.remove(key);
         js_ReportOutOfMemory(cx);
         return false;
     }
 
-    /*
-     * 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.
-     */
+    /* Since error deletes |shared|, only guard |shared| on success. */
     g->init(*shared.forget());
     return true;
 }
 
 bool
 RegExpCompartment::get(JSContext *cx, JSAtom *atom, JSString *opt, RegExpGuard *g)
 {
     RegExpFlag flags = RegExpFlag(0);