| Index: runtime/vm/object.cc
|
| diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
|
| index 43620a8200584ffe9d1ada17b62cd7e14fbb7678..3a45edf9bf946230095921753dafe12b4d63331c 100644
|
| --- a/runtime/vm/object.cc
|
| +++ b/runtime/vm/object.cc
|
| @@ -6889,13 +6889,25 @@ RawInstance* Function::ImplicitInstanceClosure(const Instance& receiver) const {
|
| *this, context);
|
| }
|
|
|
| -intptr_t Function::ComputeClosureHash() 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()) {
|
| + 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();
|
| - return result;
|
| + // 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(NameVisibility name_visibility) const {
|
| @@ -7315,6 +7327,10 @@ void ClosureData::set_implicit_static_closure(const Instance& closure) const {
|
| StorePointer(&raw_ptr()->closure_, closure.raw());
|
| }
|
|
|
| +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());
|
| }
|
| @@ -14864,10 +14880,6 @@ RawObject* Instance::HashCode() const {
|
| return DartLibraryCalls::HashCode(*this);
|
| }
|
|
|
| -RawObject* Instance::IdentityHashCode() const {
|
| - return DartLibraryCalls::IdentityHashCode(*this);
|
| -}
|
| -
|
| bool Instance::CanonicalizeEquals(const Instance& other) const {
|
| if (this->raw() == other.raw()) {
|
| return true; // "===".
|
| @@ -21657,36 +21669,6 @@ const char* Closure::ToCString() const {
|
| from, fun_desc);
|
| }
|
|
|
| -int64_t Closure::ComputeHash() const {
|
| - const Function& func = Function::Handle(function());
|
| - uint32_t result = 0;
|
| - if (func.IsImplicitInstanceClosureFunction()) {
|
| - // Implicit instance closures are not unqiue, so combine function's hash
|
| - // code with identityHashCode of cached receiver.
|
| - result = static_cast<uint32_t>(func.ComputeClosureHash());
|
| - const Context& context = Context::Handle(this->context());
|
| - const Object& receiver = Object::Handle(context.At(0));
|
| - const Object& receiverHash =
|
| - Object::Handle(Instance::Cast(receiver).IdentityHashCode());
|
| - if (receiverHash.IsError()) {
|
| - Exceptions::PropagateError(Error::Cast(receiverHash));
|
| - UNREACHABLE();
|
| - }
|
| - result = CombineHashes(
|
| - result, Integer::Cast(receiverHash).AsTruncatedUint32Value());
|
| - } else {
|
| - // Explicit closures and implicit static closures are unique,
|
| - // so identityHashCode of closure object is good enough.
|
| - const Object& identityHash = Object::Handle(this->IdentityHashCode());
|
| - if (identityHash.IsError()) {
|
| - Exceptions::PropagateError(Error::Cast(identityHash));
|
| - UNREACHABLE();
|
| - }
|
| - result = Integer::Cast(identityHash).AsTruncatedUint32Value();
|
| - }
|
| - return FinalizeHash(result, String::kHashBits);
|
| -}
|
| -
|
| RawClosure* Closure::New(const TypeArguments& instantiator_type_arguments,
|
| const TypeArguments& function_type_arguments,
|
| const Function& function,
|
|
|