Chromium Code Reviews| Index: runtime/vm/object.cc |
| diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc |
| index d447c93c07974800b1b7eed09d92a695f0fbbebd..f85d4416499ba5ddc21f4b510de03405f7091c66 100644 |
| --- a/runtime/vm/object.cc |
| +++ b/runtime/vm/object.cc |
| @@ -6845,6 +6845,29 @@ RawInstance* Function::ImplicitInstanceClosure(const Instance& receiver) const { |
| } |
| +RawSmi* Function::GetClosureHashCode() const { |
| + ASSERT(IsClosureFunction()); |
| + const Object& obj = Object::Handle(raw_ptr()->data_); |
| + ASSERT(!obj.IsNull()); |
| + if (ClosureData::Cast(obj).hash() != Object::null()) { |
| + ASSERT(Object::Handle(ClosureData::Cast(obj).hash()).IsSmi()); |
|
Cutch
2016/12/21 16:49:38
Smi::RawCast already ASSERTS that the object is a
Florian Schneider
2016/12/22 10:11:17
Done.
|
| + return Smi::RawCast(ClosureData::Cast(obj).hash()); |
| + } |
| + // Hash not yet computed. Compute and cache it. |
| + const Class& cls = Class::Handle(Owner()); |
| + intptr_t result = String::Handle(name()).Hash(); |
| + result += String::Handle(Signature()).Hash(); |
| + result += String::Handle(cls.Name()).Hash(); |
| + // Finalize hash value like for strings so that it fits into a smi. |
| + result += result << 3; |
| + result ^= result >> 11; |
| + result += result << 15; |
| + result &= ((static_cast<intptr_t>(1) << String::kHashBits) - 1); |
| + ClosureData::Cast(obj).set_hash(result); |
| + return Smi::New(result); |
| +} |
| + |
| + |
| RawString* Function::BuildSignature(bool instantiate, |
| NameVisibility name_visibility, |
| const TypeArguments& instantiator) const { |
| @@ -7221,6 +7244,11 @@ void ClosureData::set_implicit_static_closure(const Instance& closure) const { |
| } |
| +void ClosureData::set_hash(intptr_t value) const { |
| + StorePointer(&raw_ptr()->hash_, static_cast<RawObject*>(Smi::New(value))); |
| +} |
| + |
| + |
| void ClosureData::set_parent_function(const Function& value) const { |
| StorePointer(&raw_ptr()->parent_function_, value.raw()); |
| } |