Reviewers: Benedikt Meurer,

Message:
bmeurer, this might be up your alley. CC littledan as he ran into perf issues
with ToLength previously.


https://codereview.chromium.org/1314493005/diff/1/src/runtime.js
File src/runtime.js (right):

https://codereview.chromium.org/1314493005/diff/1/src/runtime.js#newcode737
src/runtime.js:737: arg = TO_NUMBER_INLINE(arg);
Not sure what the state of the art is...should this be "arg = +arg"? (or
should we add a TO_NUMBER macro that does +(arg)?)

Description:
Remove unnecessary checks and runtime calls from ToLength

This should make it easier to move to using ToLength in more places to
meet ES2015 spec requirements without regressing performance. We might
also want to mark it as inlineable, but I've left that for another
patch.

Also pull 2^53 - 1 out into a macro constant instead of requiring a load
from Number.MAX_SAFE_INTEGER.

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

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

Affected files (+9, -6 lines):
  M src/macros.py
  M src/runtime.js
  M src/v8natives.js


Index: src/macros.py
diff --git a/src/macros.py b/src/macros.py
index 2cf93724102a39c5a8bf3ec1fcf8827b58a72d07..be3a6298c17493f22d91ab147caf3ec4612c2603 100644
--- a/src/macros.py
+++ b/src/macros.py
@@ -74,6 +74,9 @@ define kMaxMonth = 10000000;
 # Reflect.construct().
 define kSafeArgumentsLength = 0x800000;

+# 2^53 - 1
+define kMaxSafeInteger = 9007199254740991;
+
 # Strict mode flags for passing to %SetProperty
 define kSloppyMode = 0;
 define kStrictMode = 1;
Index: src/runtime.js
diff --git a/src/runtime.js b/src/runtime.js
index de64541496f41ac4ce59cc7836943588804a0acb..160d82cd88ab6a9682fcf416e15083611924337d 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -732,12 +732,12 @@ function ToInteger(x) {
 }


-// ES6, draft 08-24-14, section 7.1.15
+// ES6, section 7.1.15
 function ToLength(arg) {
-  arg = ToInteger(arg);
-  if (arg < 0) return 0;
-  return arg < GlobalNumber.MAX_SAFE_INTEGER ? arg
- : GlobalNumber.MAX_SAFE_INTEGER;
+  arg = TO_NUMBER_INLINE(arg);
+  if (arg <= 0) return 0;
+  arg = %_MathFloor(arg);
+  return arg < kMaxSafeInteger ? arg : kMaxSafeInteger;
 }


Index: src/v8natives.js
diff --git a/src/v8natives.js b/src/v8natives.js
index b051a044b4c532f835a2bdd16ee96c04d4236eab..2081d216079aaf7d5baa1de72f0bbfa0c1a4d264 100644
--- a/src/v8natives.js
+++ b/src/v8natives.js
@@ -1541,7 +1541,7 @@ function NumberIsSafeInteger(number) {
   if (NumberIsFinite(number)) {
     var integral = TO_INTEGER(number);
     if (integral == number) {
-      return MathAbs(integral) <= GlobalNumber.MAX_SAFE_INTEGER;
+      return MathAbs(integral) <= kMaxSafeInteger;
     }
   }
   return false;


--
--
v8-dev mailing list
v8-dev@googlegroups.com
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 v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to