Bug 1434965 - Eliminate custom StringKey class by using nsCStringHashKey. r?njn draft
authorMarkus Stange <mstange@themasta.com>
Sat, 10 Feb 2018 19:05:19 -0500
changeset 754064 a19d8f1d55841774fc94778b3f61d6698c6f8fc2
parent 754063 c6659ad26a76d967c3b7ce97b16796d32d63186f
child 754065 8b6e67d8fa47290d272e230aa9ffb51875aad2fb
push id98744
push userbmo:mstange@themasta.com
push dateMon, 12 Feb 2018 19:50:57 +0000
reviewersnjn
bugs1434965
milestone60.0a1
Bug 1434965 - Eliminate custom StringKey class by using nsCStringHashKey. r?njn MozReview-Commit-ID: HRYfXI43wmE
tools/profiler/core/ProfileBufferEntry.cpp
tools/profiler/core/ProfileBufferEntry.h
--- a/tools/profiler/core/ProfileBufferEntry.cpp
+++ b/tools/profiler/core/ProfileBufferEntry.cpp
@@ -246,28 +246,28 @@ private:
 };
 
 template<typename LambdaT> ForEachTrackedOptimizationAttemptsLambdaOp<LambdaT>
 MakeForEachTrackedOptimizationAttemptsLambdaOp(LambdaT&& aLambda)
 {
   return ForEachTrackedOptimizationAttemptsLambdaOp<LambdaT>(Move(aLambda));
 }
 
-uint32_t UniqueJSONStrings::GetOrAddIndex(const char* aStr)
+uint32_t
+UniqueJSONStrings::GetOrAddIndex(const char* aStr)
 {
-  uint32_t index;
-  StringKey key(aStr);
+  nsDependentCString str(aStr);
 
-  auto it = mStringToIndexMap.find(key);
+  uint32_t index;
+  if (mStringToIndexMap.Get(str, &index)) {
+    return index;
+  }
 
-  if (it != mStringToIndexMap.end()) {
-    return it->second;
-  }
-  index = mStringToIndexMap.size();
-  mStringToIndexMap[key] = index;
+  index = mStringToIndexMap.Count();
+  mStringToIndexMap.Put(str, index);
   mStringTableWriter.StringElement(aStr);
   return index;
 }
 
 bool UniqueStacks::FrameKey::operator==(const FrameKey& aOther) const
 {
   return mLocation == aOther.mLocation &&
          mLine == aOther.mLine &&
--- a/tools/profiler/core/ProfileBufferEntry.h
+++ b/tools/profiler/core/ProfileBufferEntry.h
@@ -132,49 +132,19 @@ public:
   }
 
   void WriteElement(mozilla::JSONWriter& aWriter, const char* aStr) {
     aWriter.IntElement(GetOrAddIndex(aStr));
   }
 
   uint32_t GetOrAddIndex(const char* aStr);
 
-  struct StringKey {
-
-    explicit StringKey(const char* aStr)
-     : mStr(strdup(aStr))
-    {
-      mHash = mozilla::HashString(mStr);
-    }
-
-    StringKey(const StringKey& aOther)
-      : mStr(strdup(aOther.mStr))
-    {
-      mHash = aOther.mHash;
-    }
-
-    ~StringKey() {
-      free(mStr);
-    }
-
-    uint32_t Hash() const;
-    bool operator==(const StringKey& aOther) const {
-      return strcmp(mStr, aOther.mStr) == 0;
-    }
-    bool operator<(const StringKey& aOther) const {
-      return mHash < aOther.mHash;
-    }
-
-  private:
-    uint32_t mHash;
-    char* mStr;
-  };
 private:
   SpliceableChunkedJSONWriter mStringTableWriter;
-  std::map<StringKey, uint32_t> mStringToIndexMap;
+  nsDataHashtable<nsCStringHashKey, uint32_t> mStringToIndexMap;
 };
 
 class UniqueStacks
 {
 public:
   struct FrameKey {
     // This cannot be a std::string, as it is not memmove compatible, which
     // is used by nsHashTable