Bug 925949: Add fastpath to zeroLastIndex the normal RegExpObject, r=jwalden a=akeybl
authorHannes Verschore <hv1989@gmail.com>
Fri, 01 Nov 2013 14:47:44 +0100
changeset 167304 8f6d7f3350c3e3cfcd1c6799be7925f5d770ab1b
parent 167303 27d0165a1097d1dab32e45bf0fb03a55be446129
child 167305 12e87b3b86c63ec13d26a2f9fb17595261301461
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden, akeybl
bugs925949
milestone27.0a2
Bug 925949: Add fastpath to zeroLastIndex the normal RegExpObject, r=jwalden a=akeybl
js/src/jsstr.cpp
--- a/js/src/jsstr.cpp
+++ b/js/src/jsstr.cpp
@@ -1783,18 +1783,24 @@ class MOZ_STACK_CLASS StringRegExpGuard
 
         return cx->compartment()->regExps.get(cx, patstr, opt, &re_);
     }
 
     bool zeroLastIndex(JSContext *cx) {
         if (!regExpIsObject())
             return true;
 
-        // Don't use RegExpObject::setLastIndex, because that ignores the
-        // writability of "lastIndex" on this user-controlled RegExp object.
+        // Use a fast path for same-global RegExp objects with writable
+        // lastIndex.
+        if (obj_->is<RegExpObject>() && obj_->nativeLookup(cx, cx->names().lastIndex)->writable()) {
+            obj_->as<RegExpObject>().zeroLastIndex();
+            return true;
+        }
+
+        // Handle everything else generically (including throwing if .lastIndex is non-writable).
         RootedValue zero(cx, Int32Value(0));
         return JSObject::setProperty(cx, obj_, obj_, cx->names().lastIndex, &zero, true);
     }
 
     RegExpShared &regExp() { return *re_; }
 
     bool regExpIsObject() { return obj_ != nullptr; }
     HandleObject regExpObject() {