Bug 1388354 - Optimize ToPropertyKey a bit. r=anba
authorJan de Mooij <jdemooij@mozilla.com>
Thu, 10 Aug 2017 11:11:42 +0200
changeset 373960 973ca5df0887528178b758e0525937ba3e048555
parent 373959 165a764bb2ed32ff8ee2f663141e28da775e8fdc
child 373961 4d85d37d083cd5614fe1cb1fd6029cfffc0db2d8
push id32311
push userkwierso@gmail.com
push dateFri, 11 Aug 2017 01:14:57 +0000
treeherdermozilla-central@253a8560dc34 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersanba
bugs1388354
milestone57.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 1388354 - Optimize ToPropertyKey a bit. r=anba
js/src/jsobj.cpp
js/src/jsobjinlines.h
--- a/js/src/jsobj.cpp
+++ b/js/src/jsobj.cpp
@@ -3171,16 +3171,30 @@ js::ToPrimitiveSlow(JSContext* cx, JSTyp
         if (vp.isObject())
             return ReportCantConvert(cx, JSMSG_TOPRIMITIVE_RETURNED_OBJECT, obj, preferredType);
         return true;
     }
 
     return OrdinaryToPrimitive(cx, obj, preferredType, vp);
 }
 
+/* ES6 draft rev 28 (2014 Oct 14) 7.1.14 */
+bool
+js::ToPropertyKeySlow(JSContext* cx, HandleValue argument, MutableHandleId result)
+{
+    MOZ_ASSERT(argument.isObject());
+
+    // Steps 1-2.
+    RootedValue key(cx, argument);
+    if (!ToPrimitiveSlow(cx, JSTYPE_STRING, &key))
+        return false;
+
+    // Steps 3-4.
+    return ValueToId<CanGC>(cx, key, result);
+}
 
 /* * */
 
 bool
 js::IsDelegate(JSContext* cx, HandleObject obj, const js::Value& v, bool* result)
 {
     if (v.isPrimitive()) {
         *result = false;
--- a/js/src/jsobjinlines.h
+++ b/js/src/jsobjinlines.h
@@ -578,27 +578,27 @@ HasNoToPrimitiveMethodPure(JSObject* obj
     JSObject* pobj;
     PropertyResult prop;
     if (!LookupPropertyPure(cx, obj, id, &pobj, &prop))
         return false;
 
     return !prop;
 }
 
+extern bool
+ToPropertyKeySlow(JSContext* cx, HandleValue argument, MutableHandleId result);
+
 /* ES6 draft rev 28 (2014 Oct 14) 7.1.14 */
-inline bool
+MOZ_ALWAYS_INLINE bool
 ToPropertyKey(JSContext* cx, HandleValue argument, MutableHandleId result)
 {
-    // Steps 1-2.
-    RootedValue key(cx, argument);
-    if (!ToPrimitive(cx, JSTYPE_STRING, &key))
-        return false;
+    if (MOZ_LIKELY(argument.isPrimitive()))
+        return ValueToId<CanGC>(cx, argument, result);
 
-    // Steps 3-4.
-    return ValueToId<CanGC>(cx, key, result);
+    return ToPropertyKeySlow(cx, argument, result);
 }
 
 /*
  * Return true if this is a compiler-created internal function accessed by
  * its own object. Such a function object must not be accessible to script
  * or embedding code.
  */
 inline bool