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
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)),