Reviewers: Vyacheslav Egorov,
Description:
Fix the logic that should ensure that a string cannot have
a hash key of zero.
Please review this at http://codereview.chromium.org/9113006/
SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/
Affected files:
M src/objects-inl.h
M src/objects.h
M src/objects.cc
Index: src/objects-inl.h
===================================================================
--- src/objects-inl.h (revision 10330)
+++ src/objects-inl.h (working copy)
@@ -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;
Index: src/objects.cc
===================================================================
--- src/objects.cc (revision 10330)
+++ src/objects.cc (working copy)
@@ -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);
Index: src/objects.h
===================================================================
--- src/objects.h (revision 10330)
+++ src/objects.h (working copy)
@@ -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