Reviewers: ,

Message:
yangguo, ptal

Description:
Refactoring: HashMap: provide a pointer match function, so users don't need to.

BUG=yang...@chromium.org

Please review this at https://codereview.chromium.org/239133002/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+15, -34 lines):
  M src/allocation-tracker.cc
  M src/bootstrapper.cc
  M src/debug.h
  M src/hashmap.h
  M src/heap-snapshot-generator.h
  M src/heap-snapshot-generator.cc
  M src/serialize.h
  M src/serialize.cc


Index: src/allocation-tracker.cc
diff --git a/src/allocation-tracker.cc b/src/allocation-tracker.cc
index a9103a84a37bd7d025248284f65862ca659a09db..ce530d144abf85422dbe60e04e0577e55e342fd6 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)";
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index ba08aade83504d3848ad43347c08ccef94d8884e..cac88b5c18a81835520a48f1f55a9be8fe5c162b 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -2178,12 +2178,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) {
Index: src/debug.h
diff --git a/src/debug.h b/src/debug.h
index 8a793a74facacb6e8ff142ea169e1ba63915d78a..3761fde55b86348f06968f37f8bf8e7ea25d97ed 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();

Index: src/hashmap.h
diff --git a/src/hashmap.h b/src/hashmap.h
index 11f6ace7d8384ce0c754452125c2524715a6e301..65ca7a5f2c00dfe08e48e32a053d0472af78071a 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_;
Index: src/heap-snapshot-generator.cc
diff --git a/src/heap-snapshot-generator.cc b/src/heap-snapshot-generator.cc
index 0f3e6ad413f270719dc546e792aa45ce8ebf73bc..545e990e1a1d35d723045d1851ed52fabcc7b26a 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) {
 }


Index: src/heap-snapshot-generator.h
diff --git a/src/heap-snapshot-generator.h b/src/heap-snapshot-generator.h
index 1582b2e1e85a94e9a518c2392a51370a59b41d37..b34658d95523bc11a9260acf69383b235f5b6b6b 100644
--- a/src/heap-snapshot-generator.h
+++ b/src/heap-snapshot-generator.h
@@ -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_;

Index: src/serialize.cc
diff --git a/src/serialize.cc b/src/serialize.cc
index 4048886fdb76b5a499a4fb83670924fc998c4b2e..045942d508d558bb5d7fa705ae55fa1844bf1f35 100644
--- a/src/serialize.cc
+++ b/src/serialize.cc
@@ -575,7 +575,7 @@ void ExternalReferenceTable::PopulateTable(Isolate* isolate) {


 ExternalReferenceEncoder::ExternalReferenceEncoder(Isolate* isolate)
-    : encodings_(Match),
+    : encodings_(HashMap::PointersMatch),
       isolate_(isolate) {
   ExternalReferenceTable* external_references =
       ExternalReferenceTable::instance(isolate_);
@@ -669,7 +669,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)) {
@@ -709,10 +709,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) {
Index: src/serialize.h
diff --git a/src/serialize.h b/src/serialize.h
index 2947144750a964611de563cfb4f0f8ffa4029929..1fc125bcd38188e1540dc532a223a2bea6c061d7 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<int32_t>(reinterpret_cast<intptr_t>(obj->address()));
   }


--
--
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to