From 8b9fd69616a1c70d4b6bc1b58b3772d998149a17 Mon Sep 17 00:00:00 2001 From: "marja@chromium.org" Date: Tue, 15 Apr 2014 14:48:21 +0000 Subject: [PATCH] Refactoring: HashMap: provide a pointer match function, so users don't need to. R=yangguo@chromium.org Review URL: https://codereview.chromium.org/239133002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20773 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/allocation-tracker.cc | 7 +------ src/bootstrapper.cc | 7 +------ src/debug.h | 7 +++---- src/hashmap.h | 5 +++++ src/heap-snapshot-generator.cc | 4 ++-- src/heap-snapshot-generator.h | 3 --- src/serialize.cc | 8 ++------ src/serialize.h | 8 +------- 8 files changed, 15 insertions(+), 34 deletions(-) diff --git a/src/allocation-tracker.cc b/src/allocation-tracker.cc index a9103a8..ce530d1 100644 --- a/src/allocation-tracker.cc +++ b/src/allocation-tracker.cc @@ -211,11 +211,6 @@ void AddressToTraceMap::RemoveRange(Address start, Address end) { } -static bool AddressesMatch(void* key1, void* key2) { - return key1 == key2; -} - - void AllocationTracker::DeleteFunctionInfo(FunctionInfo** info) { delete *info; } @@ -225,7 +220,7 @@ AllocationTracker::AllocationTracker( HeapObjectsMap* ids, StringsStorage* names) : ids_(ids), names_(names), - id_to_function_info_index_(AddressesMatch), + id_to_function_info_index_(HashMap::PointersMatch), info_index_for_other_state_(0) { FunctionInfo* info = new FunctionInfo(); info->name = "(root)"; diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index 71672d7..45f55f8 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -2179,12 +2179,7 @@ static uint32_t Hash(RegisteredExtension* extension) { } -static bool MatchRegisteredExtensions(void* key1, void* key2) { - return key1 == key2; -} - -Genesis::ExtensionStates::ExtensionStates() - : map_(MatchRegisteredExtensions, 8) { } +Genesis::ExtensionStates::ExtensionStates() : map_(HashMap::PointersMatch, 8) {} Genesis::ExtensionTraversalState Genesis::ExtensionStates::get_state( RegisteredExtension* extension) { diff --git a/src/debug.h b/src/debug.h index 8a793a7..3761fde 100644 --- a/src/debug.h +++ b/src/debug.h @@ -175,7 +175,9 @@ class BreakLocationIterator { class ScriptCache : private HashMap { public: explicit ScriptCache(Isolate* isolate) - : HashMap(ScriptMatch), isolate_(isolate), collected_scripts_(10) {} + : HashMap(HashMap::PointersMatch), + isolate_(isolate), + collected_scripts_(10) {} virtual ~ScriptCache() { Clear(); } // Add script to the cache. @@ -193,9 +195,6 @@ class ScriptCache : private HashMap { return ComputeIntegerHash(key, v8::internal::kZeroHashSeed); } - // Scripts match if their keys (script id) match. - static bool ScriptMatch(void* key1, void* key2) { return key1 == key2; } - // Clear the cache releasing all the weak handles. void Clear(); diff --git a/src/hashmap.h b/src/hashmap.h index 11f6ace..65ca7a5 100644 --- a/src/hashmap.h +++ b/src/hashmap.h @@ -98,6 +98,11 @@ class TemplateHashMapImpl { Entry* Start() const; Entry* Next(Entry* p) const; + // Some match functions defined for convenience. + static bool PointersMatch(void* key1, void* key2) { + return key1 == key2; + } + private: MatchFun match_; Entry* map_; diff --git a/src/heap-snapshot-generator.cc b/src/heap-snapshot-generator.cc index 0f3e6ad..545e990 100644 --- a/src/heap-snapshot-generator.cc +++ b/src/heap-snapshot-generator.cc @@ -732,7 +732,7 @@ size_t HeapObjectsMap::GetUsedMemorySize() const { HeapEntriesMap::HeapEntriesMap() - : entries_(HeapThingsMatch) { + : entries_(HashMap::PointersMatch) { } @@ -751,7 +751,7 @@ void HeapEntriesMap::Pair(HeapThing thing, int entry) { HeapObjectsSet::HeapObjectsSet() - : entries_(HeapEntriesMap::HeapThingsMatch) { + : entries_(HashMap::PointersMatch) { } diff --git a/src/heap-snapshot-generator.h b/src/heap-snapshot-generator.h index 1582b2e..b34658d 100644 --- a/src/heap-snapshot-generator.h +++ b/src/heap-snapshot-generator.h @@ -315,9 +315,6 @@ class HeapEntriesMap { static_cast(reinterpret_cast(thing)), v8::internal::kZeroHashSeed); } - static bool HeapThingsMatch(HeapThing key1, HeapThing key2) { - return key1 == key2; - } HashMap entries_; diff --git a/src/serialize.cc b/src/serialize.cc index ed7f045..b271fa2 100644 --- a/src/serialize.cc +++ b/src/serialize.cc @@ -586,7 +586,7 @@ void ExternalReferenceTable::PopulateTable(Isolate* isolate) { ExternalReferenceEncoder::ExternalReferenceEncoder(Isolate* isolate) - : encodings_(Match), + : encodings_(HashMap::PointersMatch), isolate_(isolate) { ExternalReferenceTable* external_references = ExternalReferenceTable::instance(isolate_); @@ -680,7 +680,7 @@ class CodeAddressMap: public CodeEventLogger { private: class NameMap { public: - NameMap() : impl_(&PointerEquals) {} + NameMap() : impl_(HashMap::PointersMatch) {} ~NameMap() { for (HashMap::Entry* p = impl_.Start(); p != NULL; p = impl_.Next(p)) { @@ -720,10 +720,6 @@ class CodeAddressMap: public CodeEventLogger { } private: - static bool PointerEquals(void* lhs, void* rhs) { - return lhs == rhs; - } - static char* CopyName(const char* name, int name_size) { char* result = NewArray(name_size + 1); for (int i = 0; i < name_size; ++i) { diff --git a/src/serialize.h b/src/serialize.h index 2947144..1fc125b 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -124,8 +124,6 @@ class ExternalReferenceEncoder { int IndexOf(Address key) const; - static bool Match(void* key1, void* key2) { return key1 == key2; } - void Put(Address key, int index); Isolate* isolate_; @@ -414,7 +412,7 @@ class SerializationAddressMapper { public: SerializationAddressMapper() : no_allocation_(), - serialization_map_(new HashMap(&SerializationMatchFun)) { } + serialization_map_(new HashMap(HashMap::PointersMatch)) { } ~SerializationAddressMapper() { delete serialization_map_; @@ -438,10 +436,6 @@ class SerializationAddressMapper { } private: - static bool SerializationMatchFun(void* key1, void* key2) { - return key1 == key2; - } - static uint32_t Hash(HeapObject* obj) { return static_cast(reinterpret_cast(obj->address())); } -- 2.7.4