Bug 1434965 - Eliminate custom StringKey class by using nsCStringHashKey. r?njn
MozReview-Commit-ID: HRYfXI43wmE
--- 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