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 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1821 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
976a9025e4
commit
ec3beee2bf
@ -2072,7 +2072,12 @@ int v8::Object::GetIdentityHash() {
|
||||
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)),
|
||||
|
Loading…
Reference in New Issue
Block a user