Chromium Code Reviews| Index: runtime/vm/object.h |
| =================================================================== |
| --- runtime/vm/object.h (revision 17040) |
| +++ runtime/vm/object.h (working copy) |
| @@ -3900,7 +3900,21 @@ |
| intptr_t Length() const { return Smi::Value(raw_ptr()->length_); } |
| static intptr_t length_offset() { return OFFSET_OF(RawString, length_); } |
| - virtual intptr_t Hash() const; |
| + virtual intptr_t Hash() const { |
|
Ivan Posva
2013/01/15 06:05:15
Can you explain to me why Hash() is a virtual in t
srdjan
2013/01/15 18:58:28
Apparently, the reason is historical. There is no
|
| + return StringHash(); |
| + } |
| + |
| + // Non-virtual, higher performance when type is known. |
| + intptr_t StringHash() const { |
| + intptr_t result = Smi::Value(raw_ptr()->hash_); |
| + if (result != 0) { |
| + return result; |
| + } |
| + result = String::Hash(*this, 0, this->Length()); |
| + this->SetHash(result); |
| + return result; |
| + } |
| + |
| static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } |
| static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); |
| static intptr_t Hash(const uint8_t* characters, intptr_t len); |