Revision: 5420
Author: [email protected]
Date: Tue Sep  7 04:32:20 2010
Log: Removing a wrong check.

A strings which represents an array index with length 8 and 9 digits do not pass this check. However generated hash is valid.

Review URL: http://codereview.chromium.org/3295017
http://code.google.com/p/v8/source/detail?r=5420

Modified:
 /branches/bleeding_edge/src/objects.cc
 /branches/bleeding_edge/src/objects.h
 /branches/bleeding_edge/src/runtime.cc
 /branches/bleeding_edge/test/mjsunit/str-to-num.js

=======================================
--- /branches/bleeding_edge/src/objects.cc      Mon Sep  6 05:50:11 2010
+++ /branches/bleeding_edge/src/objects.cc      Tue Sep  7 04:32:20 2010
@@ -4988,17 +4988,20 @@
 }


-uint32_t StringHasher::MakeCachedArrayIndex(uint32_t value, int length) {
-  value <<= String::kHashShift;
+uint32_t StringHasher::MakeArrayIndexHash(uint32_t value, int length) {
   // For array indexes mix the length into the hash as an array index could
   // be zero.
   ASSERT(length > 0);
   ASSERT(length <= String::kMaxArrayIndexSize);
   ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) <
          (1 << String::kArrayIndexValueBits));
-  ASSERT(String::kMaxArrayIndexSize < (1 << String::kArrayIndexValueBits));
-  value &= ~String::kIsNotArrayIndexMask;
+
+  value <<= String::kHashShift;
   value |= length << String::kArrayIndexHashLengthShift;
+
+  ASSERT((value & String::kIsNotArrayIndexMask) == 0);
+  ASSERT((length > String::kMaxCachedArrayIndexLength) ||
+         (value & String::kContainsCachedArrayIndexMask) == 0);
   return value;
 }

@@ -5007,7 +5010,7 @@
   ASSERT(is_valid());
   if (length_ <= String::kMaxHashCalcLength) {
     if (is_array_index()) {
-      return MakeCachedArrayIndex(array_index(), length_);
+      return MakeArrayIndexHash(array_index(), length_);
     }
return (GetHash() << String::kHashShift) | String::kIsNotArrayIndexMask;
   } else {
=======================================
--- /branches/bleeding_edge/src/objects.h       Mon Sep  6 05:50:11 2010
+++ /branches/bleeding_edge/src/objects.h       Tue Sep  7 04:32:20 2010
@@ -4223,7 +4223,7 @@
   // Calculated hash value for a string consisting of 1 to
   // String::kMaxArrayIndexSize digits with no leading zeros (except "0").
   // value is represented decimal value.
-  static uint32_t MakeCachedArrayIndex(uint32_t value, int length);
+  static uint32_t MakeArrayIndexHash(uint32_t value, int length);

  private:

@@ -4467,6 +4467,7 @@
       kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields;

   STATIC_CHECK((kArrayIndexLengthBits > 0));
+  STATIC_CHECK(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits));

   static const int kArrayIndexHashLengthShift =
       kArrayIndexValueBits + kNofHashBitFields;
=======================================
--- /branches/bleeding_edge/src/runtime.cc      Tue Aug 31 03:39:02 2010
+++ /branches/bleeding_edge/src/runtime.cc      Tue Sep  7 04:32:20 2010
@@ -4677,9 +4677,8 @@
                  (len == 1 || data[0] != '0')) {
         // String hash is not calculated yet but all the data are present.
         // Update the hash field to speed up sequential convertions.
-        uint32_t hash = StringHasher::MakeCachedArrayIndex(d, len);
+        uint32_t hash = StringHasher::MakeArrayIndexHash(d, len);
 #ifdef DEBUG
-        ASSERT((hash & String::kContainsCachedArrayIndexMask) == 0);
         subject->Hash();  // Force hash calculation.
         ASSERT_EQ(static_cast<int>(subject->hash_field()),
                   static_cast<int>(hash));
=======================================
--- /branches/bleeding_edge/test/mjsunit/str-to-num.js Wed Mar 31 10:19:05 2010 +++ /branches/bleeding_edge/test/mjsunit/str-to-num.js Tue Sep 7 04:32:20 2010
@@ -203,3 +203,7 @@
 assertTrue(isNaN(toNumber("1e")), "1e");
 assertTrue(isNaN(toNumber("1e ")), "1e_");
assertTrue(isNaN(toNumber("1" + repeat('0', 1000) + 'junk')), "1e1000 junk");
+
+for (var i = 1; i < 12; i++) {
+  assertEquals(toNumber('1' + repeat('0', i)), Math.pow(10.0, i));
+}

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

Reply via email to