Revision: 10338
Author:   [email protected]
Date:     Thu Jan  5 02:18:28 2012
Log:      Fix the logic that should ensure that a string cannot have
a hash key of zero.
Review URL: http://codereview.chromium.org/9113006
http://code.google.com/p/v8/source/detail?r=10338

Modified:
 /branches/bleeding_edge/src/objects-inl.h
 /branches/bleeding_edge/src/objects.cc
 /branches/bleeding_edge/src/objects.h

=======================================
--- /branches/bleeding_edge/src/objects-inl.h   Wed Jan  4 07:12:15 2012
+++ /branches/bleeding_edge/src/objects-inl.h   Thu Jan  5 02:18:28 2012
@@ -4381,7 +4381,7 @@
   result += (result << 3);
   result ^= (result >> 11);
   result += (result << 15);
-  if (result == 0) {
+  if ((result & String::kHashBitMask) == 0) {
     result = 27;
   }
   return result;
=======================================
--- /branches/bleeding_edge/src/objects.cc      Wed Jan  4 07:12:15 2012
+++ /branches/bleeding_edge/src/objects.cc      Thu Jan  5 02:18:28 2012
@@ -11444,7 +11444,7 @@
     hash += hash << 3;
     hash ^= hash >> 11;
     hash += hash << 15;
-    if (hash == 0) hash = 27;
+    if ((hash & String::kHashBitMask) == 0) hash = 27;
 #ifdef DEBUG
     StringHasher hasher(2, seed);
     hasher.AddCharacter(c1);
=======================================
--- /branches/bleeding_edge/src/objects.h       Wed Jan  4 09:29:01 2012
+++ /branches/bleeding_edge/src/objects.h       Thu Jan  5 02:18:28 2012
@@ -6459,6 +6459,10 @@
   // Shift constant retrieving hash code from hash field.
   static const int kHashShift = kNofHashBitFields;

+ // Only these bits are relevant in the hash, since the top two are shifted
+  // out.
+  static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift;
+
   // Array index strings this short can keep their index in the hash
   // field.
   static const int kMaxCachedArrayIndexLength = 7;

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

Reply via email to