Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(541)

Side by Side Diff: runtime/vm/object.cc

Issue 2983823002: Improve hashCode for closures (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/become.h" 10 #include "vm/become.h"
(...skipping 6884 matching lines...) Expand 10 before | Expand all | Expand 10 after
6895 if (!HasInstantiatedSignature(kCurrentClass)) { 6895 if (!HasInstantiatedSignature(kCurrentClass)) {
6896 instantiator_type_arguments = receiver.GetTypeArguments(); 6896 instantiator_type_arguments = receiver.GetTypeArguments();
6897 } 6897 }
6898 if (!HasInstantiatedSignature(kFunctions)) { 6898 if (!HasInstantiatedSignature(kFunctions)) {
6899 function_type_arguments = Object::empty_type_arguments().raw(); 6899 function_type_arguments = Object::empty_type_arguments().raw();
6900 } 6900 }
6901 return Closure::New(instantiator_type_arguments, function_type_arguments, 6901 return Closure::New(instantiator_type_arguments, function_type_arguments,
6902 *this, context); 6902 *this, context);
6903 } 6903 }
6904 6904
6905 RawSmi* Function::GetClosureHashCode() const { 6905 intptr_t Function::GetClosureHashCode() const {
rmacnak 2017/07/19 01:00:24 GetHash -> ComputeHash
alexmarkov 2017/07/19 17:54:19 Done: GetClosureHashCode is renamed to ComputeClos
6906 ASSERT(IsClosureFunction()); 6906 ASSERT(IsClosureFunction());
6907 const Object& obj = Object::Handle(raw_ptr()->data_);
6908 ASSERT(!obj.IsNull());
6909 if (ClosureData::Cast(obj).hash() != Object::null()) {
6910 return Smi::RawCast(ClosureData::Cast(obj).hash());
6911 }
6912 // Hash not yet computed. Compute and cache it.
6913 const Class& cls = Class::Handle(Owner()); 6907 const Class& cls = Class::Handle(Owner());
6914 intptr_t result = String::Handle(name()).Hash(); 6908 intptr_t result = String::Handle(name()).Hash();
6915 result += String::Handle(Signature()).Hash(); 6909 result += String::Handle(Signature()).Hash();
6916 result += String::Handle(cls.Name()).Hash(); 6910 result += String::Handle(cls.Name()).Hash();
6917 // Finalize hash value like for strings so that it fits into a smi. 6911 return result;
6918 result += result << 3;
6919 result ^= result >> 11;
6920 result += result << 15;
6921 result &= ((static_cast<intptr_t>(1) << String::kHashBits) - 1);
6922 ClosureData::Cast(obj).set_hash(result);
6923 return Smi::New(result);
6924 } 6912 }
6925 6913
6926 RawString* Function::BuildSignature(NameVisibility name_visibility) const { 6914 RawString* Function::BuildSignature(NameVisibility name_visibility) const {
6927 Thread* thread = Thread::Current(); 6915 Thread* thread = Thread::Current();
6928 Zone* zone = thread->zone(); 6916 Zone* zone = thread->zone();
6929 GrowableHandlePtrArray<const String> pieces(zone, 4); 6917 GrowableHandlePtrArray<const String> pieces(zone, 4);
6930 String& name = String::Handle(zone); 6918 String& name = String::Handle(zone);
6931 if (FLAG_reify_generic_functions) { 6919 if (FLAG_reify_generic_functions) {
6932 const TypeArguments& type_params = 6920 const TypeArguments& type_params =
6933 TypeArguments::Handle(zone, type_parameters()); 6921 TypeArguments::Handle(zone, type_parameters());
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
7323 void ClosureData::set_context_scope(const ContextScope& value) const { 7311 void ClosureData::set_context_scope(const ContextScope& value) const {
7324 StorePointer(&raw_ptr()->context_scope_, value.raw()); 7312 StorePointer(&raw_ptr()->context_scope_, value.raw());
7325 } 7313 }
7326 7314
7327 void ClosureData::set_implicit_static_closure(const Instance& closure) const { 7315 void ClosureData::set_implicit_static_closure(const Instance& closure) const {
7328 ASSERT(!closure.IsNull()); 7316 ASSERT(!closure.IsNull());
7329 ASSERT(raw_ptr()->closure_ == Instance::null()); 7317 ASSERT(raw_ptr()->closure_ == Instance::null());
7330 StorePointer(&raw_ptr()->closure_, closure.raw()); 7318 StorePointer(&raw_ptr()->closure_, closure.raw());
7331 } 7319 }
7332 7320
7333 void ClosureData::set_hash(intptr_t value) const {
7334 StorePointer(&raw_ptr()->hash_, static_cast<RawObject*>(Smi::New(value)));
7335 }
7336
7337 void ClosureData::set_parent_function(const Function& value) const { 7321 void ClosureData::set_parent_function(const Function& value) const {
7338 StorePointer(&raw_ptr()->parent_function_, value.raw()); 7322 StorePointer(&raw_ptr()->parent_function_, value.raw());
7339 } 7323 }
7340 7324
7341 void ClosureData::set_signature_type(const Type& value) const { 7325 void ClosureData::set_signature_type(const Type& value) const {
7342 StorePointer(&raw_ptr()->signature_type_, value.raw()); 7326 StorePointer(&raw_ptr()->signature_type_, value.raw());
7343 } 7327 }
7344 7328
7345 RawClosureData* ClosureData::New() { 7329 RawClosureData* ClosureData::New() {
7346 ASSERT(Object::closure_data_class() != Class::null()); 7330 ASSERT(Object::closure_data_class() != Class::null());
(...skipping 7528 matching lines...) Expand 10 before | Expand all | Expand 10 after
14875 } 14859 }
14876 return DartEntry::InvokeFunction(eval_func, args); 14860 return DartEntry::InvokeFunction(eval_func, args);
14877 } 14861 }
14878 14862
14879 RawObject* Instance::HashCode() const { 14863 RawObject* Instance::HashCode() const {
14880 // TODO(koda): Optimize for all builtin classes and all classes 14864 // TODO(koda): Optimize for all builtin classes and all classes
14881 // that do not override hashCode. 14865 // that do not override hashCode.
14882 return DartLibraryCalls::HashCode(*this); 14866 return DartLibraryCalls::HashCode(*this);
14883 } 14867 }
14884 14868
14869 RawObject* Instance::IdentityHashCode() const {
14870 return DartLibraryCalls::IdentityHashCode(*this);
14871 }
14872
14885 bool Instance::CanonicalizeEquals(const Instance& other) const { 14873 bool Instance::CanonicalizeEquals(const Instance& other) const {
14886 if (this->raw() == other.raw()) { 14874 if (this->raw() == other.raw()) {
14887 return true; // "===". 14875 return true; // "===".
14888 } 14876 }
14889 14877
14890 if (other.IsNull() || (this->clazz() != other.clazz())) { 14878 if (other.IsNull() || (this->clazz() != other.clazz())) {
14891 return false; 14879 return false;
14892 } 14880 }
14893 14881
14894 { 14882 {
(...skipping 7337 matching lines...) Expand 10 before | Expand all | Expand 10 after
22232 } 22220 }
22233 return UserTag::null(); 22221 return UserTag::null();
22234 } 22222 }
22235 22223
22236 const char* UserTag::ToCString() const { 22224 const char* UserTag::ToCString() const {
22237 const String& tag_label = String::Handle(label()); 22225 const String& tag_label = String::Handle(label());
22238 return tag_label.ToCString(); 22226 return tag_label.ToCString();
22239 } 22227 }
22240 22228
22241 } // namespace dart 22229 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698