Bug 1342402 - Use optimized GetElement in JSON. r=jandem
authorTom Schuster <evilpies@gmail.com>
Mon, 27 Feb 2017 16:43:24 +0100
changeset 374096 5fe93937af04bf7ab1fee3a888d745e3dff78b6f
parent 374095 d19abdca97d43f9d8dd6fc7a7eaa9c57a5c97861
child 374097 cd39e056f488613b1cb18fc0ed981fc0db750c68
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1342402
milestone54.0a1
Bug 1342402 - Use optimized GetElement in JSON. r=jandem
js/src/jsarray.cpp
js/src/jsarrayinlines.h
js/src/json.cpp
--- a/js/src/jsarray.cpp
+++ b/js/src/jsarray.cpp
@@ -1,15 +1,15 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * vim: set ts=8 sts=4 et sw=4 tw=99:
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "jsarray.h"
+#include "jsarrayinlines.h"
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/CheckedInt.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/FloatingPoint.h"
 #include "mozilla/MathAlgorithms.h"
 
 #include <algorithm>
@@ -247,31 +247,16 @@ GetElement(JSContext* cx, HandleObject o
 }
 
 static inline bool
 GetElement(JSContext* cx, HandleObject obj, uint32_t index, bool* hole, MutableHandleValue vp)
 {
     return GetElement(cx, obj, obj, index, hole, vp);
 }
 
-static bool
-GetElement(JSContext* cx, HandleObject obj, uint32_t index, MutableHandleValue vp)
-{
-    if (index < GetAnyBoxedOrUnboxedInitializedLength(obj)) {
-        vp.set(GetAnyBoxedOrUnboxedDenseElement(obj, index));
-        if (!vp.isMagic(JS_ELEMENTS_HOLE))
-            return true;
-    }
-    if (obj->is<ArgumentsObject>()) {
-        if (obj->as<ArgumentsObject>().maybeGetElement(index, vp))
-            return true;
-    }
-    return GetElement(cx, obj, obj, index, vp);
-}
-
 bool
 ElementAdder::append(JSContext* cx, HandleValue v)
 {
     MOZ_ASSERT(index_ < length_);
     if (resObj_) {
         DenseElementResult result =
             SetOrExtendAnyBoxedOrUnboxedDenseElements(cx, resObj_, index_, v.address(), 1);
         if (result == DenseElementResult::Failure)
new file mode 100644
--- /dev/null
+++ b/js/src/jsarrayinlines.h
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * vim: set ts=8 sts=4 et sw=4 tw=99:
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef vm_jsarrayinlines_h
+#define vm_jsarrayinlines_h
+
+#include "jsarray.h"
+
+#include "jsobj.h"
+
+#include "vm/ArgumentsObject.h"
+
+#include "vm/ArgumentsObject-inl.h"
+#include "vm/UnboxedObject-inl.h"
+
+namespace js {
+
+inline bool
+GetElement(JSContext* cx, HandleObject obj, uint32_t index, MutableHandleValue vp)
+{
+    if (index < GetAnyBoxedOrUnboxedInitializedLength(obj)) {
+        vp.set(GetAnyBoxedOrUnboxedDenseElement(obj, index));
+        if (!vp.isMagic(JS_ELEMENTS_HOLE))
+            return true;
+    }
+
+    if (obj->is<ArgumentsObject>()) {
+        if (obj->as<ArgumentsObject>().maybeGetElement(index, vp))
+            return true;
+    }
+
+    return GetElement(cx, obj, obj, index, vp);
+}
+
+} // namespace js
+
+#endif // vm_jsarrayinlines_h
--- a/js/src/json.cpp
+++ b/js/src/json.cpp
@@ -18,16 +18,17 @@
 #include "jsstr.h"
 #include "jstypes.h"
 #include "jsutil.h"
 
 #include "vm/Interpreter.h"
 #include "vm/JSONParser.h"
 #include "vm/StringBuffer.h"
 
+#include "jsarrayinlines.h"
 #include "jsatominlines.h"
 #include "jsboolinlines.h"
 
 #include "vm/NativeObject-inl.h"
 
 using namespace js;
 using namespace js::gc;
 
@@ -491,17 +492,17 @@ JA(JSContext* cx, HandleObject obj, Stri
                                "fully dense (and otherwise un-indexed), *or* "
                                "all its initially-dense elements were sparsified "
                                "and the object is indexed");
                 } else {
                     MOZ_ASSERT(obj->isIndexed());
                 }
             }
 #endif
-            if (!GetElement(cx, obj, obj, i, &outputValue))
+            if (!GetElement(cx, obj, i, &outputValue))
                 return false;
             if (!PreprocessValue(cx, obj, i, &outputValue, scx))
                 return false;
             if (IsFilteredValue(outputValue)) {
                 if (!scx->sb.append("null"))
                     return false;
             } else {
                 if (!Str(cx, outputValue, scx))
@@ -639,17 +640,17 @@ js::Stringify(JSContext* cx, MutableHand
 
             /* Step 4b(iii)(5). */
             RootedValue item(cx);
             for (; k < len; k++) {
                 if (!CheckForInterrupt(cx))
                     return false;
 
                 /* Step 4b(iii)(5)(a-b). */
-                if (!GetElement(cx, replacer, replacer, k, &item))
+                if (!GetElement(cx, replacer, k, &item))
                     return false;
 
                 RootedId id(cx);
 
                 /* Step 4b(iii)(5)(c-f). */
                 if (item.isNumber()) {
                     /* Step 4b(iii)(5)(e). */
                     int32_t n;