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
This commit is contained in:
marja@chromium.org 2014-04-15 14:48:21 +00:00
parent be29476f64
commit 8b9fd69616
8 changed files with 15 additions and 34 deletions

View File

@ -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)";

View File

@ -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) {

View File

@ -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();

View File

@ -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_;

View File

@ -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) {
}

View File

@ -315,9 +315,6 @@ class HeapEntriesMap {
static_cast<uint32_t>(reinterpret_cast<uintptr_t>(thing)),
v8::internal::kZeroHashSeed);
}
static bool HeapThingsMatch(HeapThing key1, HeapThing key2) {
return key1 == key2;
}
HashMap entries_;

View File

@ -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<char>(name_size + 1);
for (int i = 0; i < name_size; ++i) {

View File

@ -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<int32_t>(reinterpret_cast<intptr_t>(obj->address()));
}