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

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

Issue 2598623002: Cache hash code for closures. (Closed)
Patch Set: remove redundant assertion Created 3 years, 12 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
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6827 matching lines...) Expand 10 before | Expand all | Expand 10 after
6838 const Instance& result = Instance::Handle(Closure::New(*this, context)); 6838 const Instance& result = Instance::Handle(Closure::New(*this, context));
6839 if (cls.IsGeneric()) { 6839 if (cls.IsGeneric()) {
6840 const TypeArguments& type_arguments = 6840 const TypeArguments& type_arguments =
6841 TypeArguments::Handle(receiver.GetTypeArguments()); 6841 TypeArguments::Handle(receiver.GetTypeArguments());
6842 result.SetTypeArguments(type_arguments); 6842 result.SetTypeArguments(type_arguments);
6843 } 6843 }
6844 return result.raw(); 6844 return result.raw();
6845 } 6845 }
6846 6846
6847 6847
6848 RawSmi* Function::GetClosureHashCode() const {
6849 ASSERT(IsClosureFunction());
6850 const Object& obj = Object::Handle(raw_ptr()->data_);
6851 ASSERT(!obj.IsNull());
6852 if (ClosureData::Cast(obj).hash() != Object::null()) {
6853 return Smi::RawCast(ClosureData::Cast(obj).hash());
6854 }
6855 // Hash not yet computed. Compute and cache it.
6856 const Class& cls = Class::Handle(Owner());
6857 intptr_t result = String::Handle(name()).Hash();
6858 result += String::Handle(Signature()).Hash();
6859 result += String::Handle(cls.Name()).Hash();
6860 // Finalize hash value like for strings so that it fits into a smi.
6861 result += result << 3;
6862 result ^= result >> 11;
6863 result += result << 15;
6864 result &= ((static_cast<intptr_t>(1) << String::kHashBits) - 1);
6865 ClosureData::Cast(obj).set_hash(result);
6866 return Smi::New(result);
6867 }
6868
6869
6848 RawString* Function::BuildSignature(bool instantiate, 6870 RawString* Function::BuildSignature(bool instantiate,
6849 NameVisibility name_visibility, 6871 NameVisibility name_visibility,
6850 const TypeArguments& instantiator) const { 6872 const TypeArguments& instantiator) const {
6851 Thread* thread = Thread::Current(); 6873 Thread* thread = Thread::Current();
6852 Zone* zone = thread->zone(); 6874 Zone* zone = thread->zone();
6853 GrowableHandlePtrArray<const String> pieces(zone, 4); 6875 GrowableHandlePtrArray<const String> pieces(zone, 4);
6854 String& name = String::Handle(zone); 6876 String& name = String::Handle(zone);
6855 if (!instantiate && !is_static() && (name_visibility == kInternalName)) { 6877 if (!instantiate && !is_static() && (name_visibility == kInternalName)) {
6856 // Prefix the signature with its scope class and type parameters, if any 6878 // Prefix the signature with its scope class and type parameters, if any
6857 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the 6879 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
7214 } 7236 }
7215 7237
7216 7238
7217 void ClosureData::set_implicit_static_closure(const Instance& closure) const { 7239 void ClosureData::set_implicit_static_closure(const Instance& closure) const {
7218 ASSERT(!closure.IsNull()); 7240 ASSERT(!closure.IsNull());
7219 ASSERT(raw_ptr()->closure_ == Instance::null()); 7241 ASSERT(raw_ptr()->closure_ == Instance::null());
7220 StorePointer(&raw_ptr()->closure_, closure.raw()); 7242 StorePointer(&raw_ptr()->closure_, closure.raw());
7221 } 7243 }
7222 7244
7223 7245
7246 void ClosureData::set_hash(intptr_t value) const {
7247 StorePointer(&raw_ptr()->hash_, static_cast<RawObject*>(Smi::New(value)));
7248 }
7249
7250
7224 void ClosureData::set_parent_function(const Function& value) const { 7251 void ClosureData::set_parent_function(const Function& value) const {
7225 StorePointer(&raw_ptr()->parent_function_, value.raw()); 7252 StorePointer(&raw_ptr()->parent_function_, value.raw());
7226 } 7253 }
7227 7254
7228 7255
7229 void ClosureData::set_signature_type(const Type& value) const { 7256 void ClosureData::set_signature_type(const Type& value) const {
7230 StorePointer(&raw_ptr()->signature_type_, value.raw()); 7257 StorePointer(&raw_ptr()->signature_type_, value.raw());
7231 } 7258 }
7232 7259
7233 7260
(...skipping 15638 matching lines...) Expand 10 before | Expand all | Expand 10 after
22872 return UserTag::null(); 22899 return UserTag::null();
22873 } 22900 }
22874 22901
22875 22902
22876 const char* UserTag::ToCString() const { 22903 const char* UserTag::ToCString() const {
22877 const String& tag_label = String::Handle(label()); 22904 const String& tag_label = String::Handle(label());
22878 return tag_label.ToCString(); 22905 return tag_label.ToCString();
22879 } 22906 }
22880 22907
22881 } // namespace dart 22908 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698