Reviewers: iposva, Description: 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. Please review this at http://codereview.chromium.org/100147 SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/ Affected files: M src/api.cc Index: src/api.cc =================================================================== --- src/api.cc (revision 1810) +++ src/api.cc (working copy) @@ -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 -~----------~----~----~----~------~----~------~--~---
