Author: [email protected]
Date: Wed Apr 29 14:44:13 2009
New Revision: 1821
Modified:
branches/bleeding_edge/src/api.cc
Log:
Make Object::GetIdentityHash() never return 0.
This is convenient when using identity hashes in data structures that
want to reserve 0 as a sentinel value, such as WebKit's WTF::HashMap.
Review URL: http://codereview.chromium.org/100147
Modified: branches/bleeding_edge/src/api.cc
==============================================================================
--- branches/bleeding_edge/src/api.cc (original)
+++ branches/bleeding_edge/src/api.cc Wed Apr 29 14:44:13 2009
@@ -2072,7 +2072,12 @@
if (hash->IsSmi()) {
hash_value = i::Smi::cast(*hash)->value();
} else {
- hash_value = random() & i::Smi::kMaxValue; // Limit range to fit a
smi.
+ int attempts = 0;
+ do {
+ hash_value = random() & i::Smi::kMaxValue; // Limit range to fit a
smi.
+ attempts++;
+ } while (hash_value == 0 && attempts < 30);
+ hash_value = hash_value != 0 ? hash_value : 1; // never return 0
i::SetProperty(hidden_props,
hash_symbol,
i::Handle<i::Object>(i::Smi::FromInt(hash_value)),
--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---