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

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

Issue 1882763002: Add usage and collision details to the hash table data structure in order to determine effectivenes… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: self-review-comments Created 4 years, 8 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/hash_table_test.cc ('k') | runtime/vm/parser.cc » ('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/cpu.h" 10 #include "vm/cpu.h"
(...skipping 2071 matching lines...) Expand 10 before | Expand all | Expand 10 after
2082 private: 2082 private:
2083 const String& name_; 2083 const String& name_;
2084 String* tmp_string_; 2084 String* tmp_string_;
2085 }; 2085 };
2086 2086
2087 2087
2088 // Traits for looking up Functions by name. 2088 // Traits for looking up Functions by name.
2089 class ClassFunctionsTraits { 2089 class ClassFunctionsTraits {
2090 public: 2090 public:
2091 static const char* Name() { return "ClassFunctionsTraits"; } 2091 static const char* Name() { return "ClassFunctionsTraits"; }
2092 static bool ReportStats() { return false; }
2092 2093
2093 // Called when growing the table. 2094 // Called when growing the table.
2094 static bool IsMatch(const Object& a, const Object& b) { 2095 static bool IsMatch(const Object& a, const Object& b) {
2095 ASSERT(a.IsFunction() && b.IsFunction()); 2096 ASSERT(a.IsFunction() && b.IsFunction());
2096 // Function objects are always canonical. 2097 // Function objects are always canonical.
2097 return a.raw() == b.raw(); 2098 return a.raw() == b.raw();
2098 } 2099 }
2099 static bool IsMatch(const FunctionName& name, const Object& obj) { 2100 static bool IsMatch(const FunctionName& name, const Object& obj) {
2100 return name.Matches(Function::Cast(obj)); 2101 return name.Matches(Function::Cast(obj));
2101 } 2102 }
(...skipping 6224 matching lines...) Expand 10 before | Expand all | Expand 10 after
8326 result.SetStream(stream); 8327 result.SetStream(stream);
8327 return result.raw(); 8328 return result.raw();
8328 } 8329 }
8329 8330
8330 8331
8331 // CompressedTokenMap maps String and LiteralToken keys to Smi values. 8332 // CompressedTokenMap maps String and LiteralToken keys to Smi values.
8332 // It also supports lookup by TokenDescriptor. 8333 // It also supports lookup by TokenDescriptor.
8333 class CompressedTokenTraits { 8334 class CompressedTokenTraits {
8334 public: 8335 public:
8335 static const char* Name() { return "CompressedTokenTraits"; } 8336 static const char* Name() { return "CompressedTokenTraits"; }
8337 static bool ReportStats() { return false; }
8336 8338
8337 static bool IsMatch(const Scanner::TokenDescriptor& descriptor, 8339 static bool IsMatch(const Scanner::TokenDescriptor& descriptor,
8338 const Object& key) { 8340 const Object& key) {
8339 if (!key.IsLiteralToken()) { 8341 if (!key.IsLiteralToken()) {
8340 return false; 8342 return false;
8341 } 8343 }
8342 const LiteralToken& token = LiteralToken::Cast(key); 8344 const LiteralToken& token = LiteralToken::Cast(key);
8343 return (token.literal() == descriptor.literal->raw()) && 8345 return (token.literal() == descriptor.literal->raw()) &&
8344 (token.kind() == descriptor.kind); 8346 (token.kind() == descriptor.kind);
8345 } 8347 }
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after
9256 ASSERT(LoadInProgress() || LoadRequested() || LoadFailed()); 9258 ASSERT(LoadInProgress() || LoadRequested() || LoadFailed());
9257 StoreNonPointer(&raw_ptr()->load_state_, RawLibrary::kLoadError); 9259 StoreNonPointer(&raw_ptr()->load_state_, RawLibrary::kLoadError);
9258 StorePointer(&raw_ptr()->load_error_, error.raw()); 9260 StorePointer(&raw_ptr()->load_error_, error.raw());
9259 } 9261 }
9260 9262
9261 9263
9262 // Traits for looking up Libraries by url in a hash set. 9264 // Traits for looking up Libraries by url in a hash set.
9263 class LibraryUrlTraits { 9265 class LibraryUrlTraits {
9264 public: 9266 public:
9265 static const char* Name() { return "LibraryUrlTraits"; } 9267 static const char* Name() { return "LibraryUrlTraits"; }
9268 static bool ReportStats() { return false; }
9266 9269
9267 // Called when growing the table. 9270 // Called when growing the table.
9268 static bool IsMatch(const Object& a, const Object& b) { 9271 static bool IsMatch(const Object& a, const Object& b) {
9269 ASSERT(a.IsLibrary() && b.IsLibrary()); 9272 ASSERT(a.IsLibrary() && b.IsLibrary());
9270 // Library objects are always canonical. 9273 // Library objects are always canonical.
9271 return a.raw() == b.raw(); 9274 return a.raw() == b.raw();
9272 } 9275 }
9273 static uword Hash(const Object& key) { 9276 static uword Hash(const Object& key) {
9274 return Library::Cast(key).UrlHash(); 9277 return Library::Cast(key).UrlHash();
9275 } 9278 }
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
9567 } 9570 }
9568 } 9571 }
9569 AddToResolvedNamesCache(name, obj); 9572 AddToResolvedNamesCache(name, obj);
9570 return obj.raw(); 9573 return obj.raw();
9571 } 9574 }
9572 9575
9573 9576
9574 class StringEqualsTraits { 9577 class StringEqualsTraits {
9575 public: 9578 public:
9576 static const char* Name() { return "StringEqualsTraits"; } 9579 static const char* Name() { return "StringEqualsTraits"; }
9580 static bool ReportStats() { return false; }
9577 9581
9578 static bool IsMatch(const Object& a, const Object& b) { 9582 static bool IsMatch(const Object& a, const Object& b) {
9579 return String::Cast(a).Equals(String::Cast(b)); 9583 return String::Cast(a).Equals(String::Cast(b));
9580 } 9584 }
9581 static uword Hash(const Object& obj) { 9585 static uword Hash(const Object& obj) {
9582 return String::Cast(obj).Hash(); 9586 return String::Cast(obj).Hash();
9583 } 9587 }
9584 }; 9588 };
9585 typedef UnorderedHashMap<StringEqualsTraits> ResolvedNamesMap; 9589 typedef UnorderedHashMap<StringEqualsTraits> ResolvedNamesMap;
9586 9590
(...skipping 11352 matching lines...) Expand 10 before | Expand all | Expand 10 after
20939 return "_GrowableList NULL"; 20943 return "_GrowableList NULL";
20940 } 20944 }
20941 return OS::SCreate(Thread::Current()->zone(), 20945 return OS::SCreate(Thread::Current()->zone(),
20942 "Instance(length:%" Pd ") of '_GrowableList'", Length()); 20946 "Instance(length:%" Pd ") of '_GrowableList'", Length());
20943 } 20947 }
20944 20948
20945 20949
20946 // Equivalent to Dart's operator "==" and hashCode. 20950 // Equivalent to Dart's operator "==" and hashCode.
20947 class DefaultHashTraits { 20951 class DefaultHashTraits {
20948 public: 20952 public:
20953 static const char* Name() { return "DefaultHashTraits"; }
20954 static bool ReportStats() { return false; }
20955
20949 static bool IsMatch(const Object& a, const Object& b) { 20956 static bool IsMatch(const Object& a, const Object& b) {
20950 if (a.IsNull() || b.IsNull()) { 20957 if (a.IsNull() || b.IsNull()) {
20951 return (a.IsNull() && b.IsNull()); 20958 return (a.IsNull() && b.IsNull());
20952 } else { 20959 } else {
20953 return Instance::Cast(a).OperatorEquals(Instance::Cast(b)); 20960 return Instance::Cast(a).OperatorEquals(Instance::Cast(b));
20954 } 20961 }
20955 } 20962 }
20956 static uword Hash(const Object& obj) { 20963 static uword Hash(const Object& obj) {
20957 if (obj.IsNull()) { 20964 if (obj.IsNull()) {
20958 return 0; 20965 return 0;
(...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after
22022 return UserTag::null(); 22029 return UserTag::null();
22023 } 22030 }
22024 22031
22025 22032
22026 const char* UserTag::ToCString() const { 22033 const char* UserTag::ToCString() const {
22027 const String& tag_label = String::Handle(label()); 22034 const String& tag_label = String::Handle(label());
22028 return tag_label.ToCString(); 22035 return tag_label.ToCString();
22029 } 22036 }
22030 22037
22031 } // namespace dart 22038 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/hash_table_test.cc ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698