Reviewers: Lasse Reichstein,

Description:
Small optimizations to parseInt:
- Second argument to Runtime_StringParseInt is always a smi, avoid  
converting to
double and back to int

- parseInt(positive float) is more common than parseInt(negative float), so
check for positive numbers first.

Please review this at http://codereview.chromium.org/391014

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
   M     src/runtime.cc
   M     src/v8natives.js


Index: src/v8natives.js
===================================================================
--- src/v8natives.js    (revision 3247)
+++ src/v8natives.js    (working copy)
@@ -95,8 +95,8 @@
      // they make parseInt on a string 1.4% slower (274ns vs 270ns).
      if (%_IsSmi(string)) return string;
      if (IS_NUMBER(string) &&
-        ((string < -0.01 && -1e9 < string) ||
-            (0.01 < string && string < 1e9))) {
+        ((0.01 < string && string < 1e9) ||
+            (string < -0.01 && -1e9 < string))) {
        // Truncate number.
        return string | 0;
      }
Index: src/runtime.cc
===================================================================
--- src/runtime.cc      (revision 3247)
+++ src/runtime.cc      (working copy)
@@ -3387,8 +3387,7 @@
    NoHandleAllocation ha;

    CONVERT_CHECKED(String, s, args[0]);
-  CONVERT_DOUBLE_CHECKED(n, args[1]);
-  int radix = FastD2I(n);
+  CONVERT_SMI_CHECKED(radix, args[1]);

    s->TryFlattenIfNotFlat();




--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to