Reviewers: rossberg,

Message:
This seems to give about 3% back.

Description:
Optimise ToNumber and NonNumberToNumber.

Defers some uncommon type checking from ToNumber and
NonNumberToNumber into DefaultNumber. This should
speed up numeric operations as more "value types" are
added.

LOG=N
BUG=513196, v8:4124

Please review this at https://codereview.chromium.org/1260273002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+11, -16 lines):
  M src/runtime.js


Index: src/runtime.js
diff --git a/src/runtime.js b/src/runtime.js
index dd776dbc8c354722c692c3580914398e5de26d30..799f2d807e428f8b2b901e5503922156878dc95e 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -792,8 +792,6 @@ function ToNumber(x) {
   }
   if (IS_BOOLEAN(x)) return x ? 1 : 0;
   if (IS_UNDEFINED(x)) return NAN;
-  if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToNumber);
-  if (IS_FLOAT32X4(x)) throw MakeTypeError(kSimdToNumber);
   return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x));
 }

@@ -804,8 +802,6 @@ function NonNumberToNumber(x) {
   }
   if (IS_BOOLEAN(x)) return x ? 1 : 0;
   if (IS_UNDEFINED(x)) return NAN;
-  if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToNumber);
-  if (IS_FLOAT32X4(x)) throw MakeTypeError(kSimdToNumber);
   return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x));
 }

@@ -944,18 +940,17 @@ function IsConcatSpreadable(O) {

 // ECMA-262, section 8.6.2.6, page 28.
 function DefaultNumber(x) {
-  if (!IS_SYMBOL_WRAPPER(x) && !IS_FLOAT32X4_WRAPPER(x)) {
-    var valueOf = x.valueOf;
-    if (IS_SPEC_FUNCTION(valueOf)) {
-      var v = %_CallFunction(x, valueOf);
-      if (IsPrimitive(v)) return v;
-    }
-
-    var toString = x.toString;
-    if (IS_SPEC_FUNCTION(toString)) {
-      var s = %_CallFunction(x, toString);
-      if (IsPrimitive(s)) return s;
-    }
+  var valueOf = x.valueOf;
+  if (IS_SPEC_FUNCTION(valueOf)) {
+    var v = %_CallFunction(x, valueOf);
+    if (IS_SYMBOL(v)) throw MakeTypeError(kSymbolToNumber);
+    if (IS_FLOAT32X4(v)) throw MakeTypeError(kSimdToNumber);
+    if (IsPrimitive(v)) return v;
+  }
+  var toString = x.toString;
+  if (IS_SPEC_FUNCTION(toString)) {
+    var s = %_CallFunction(x, toString);
+    if (IsPrimitive(s)) return s;
   }
   throw MakeTypeError(kCannotConvertToPrimitive);
 }


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to