Bug 1429904 - Make FrameKey members const. r?njn draft
authorMarkus Stange <mstange@themasta.com>
Sat, 17 Feb 2018 12:34:12 -0500
changeset 756756 e21a6914987df58cb0a19ed317982d41ec073f6e
parent 756755 3189a947197e2cabbb56963a288ace0af4d042ef
child 756757 0500365f7082efd721711b334b2e05993f8a10dd
push id99540
push userbmo:mstange@themasta.com
push dateSun, 18 Feb 2018 00:10:32 +0000
reviewersnjn
bugs1429904
milestone60.0a1
Bug 1429904 - Make FrameKey members const. r?njn MozReview-Commit-ID: Hls5ecronv0
tools/profiler/core/ProfileBufferEntry.cpp
tools/profiler/core/ProfileBufferEntry.h
--- a/tools/profiler/core/ProfileBufferEntry.cpp
+++ b/tools/profiler/core/ProfileBufferEntry.cpp
@@ -863,29 +863,30 @@ ProfileBuffer::StreamSamplesToJSON(Splic
             }
             e.Next();
           } else {
             break;
           }
         }
         strbuf[kMaxFrameKeyLength - 1] = '\0';
 
-        UniqueStacks::FrameKey frameKey(strbuf.get());
-
+        Maybe<unsigned> line;
         if (e.Has() && e.Get().IsLineNumber()) {
-          frameKey.mLine = Some(unsigned(e.Get().u.mInt));
+          line = Some(unsigned(e.Get().u.mInt));
           e.Next();
         }
 
+        Maybe<unsigned> category;
         if (e.Has() && e.Get().IsCategory()) {
-          frameKey.mCategory = Some(unsigned(e.Get().u.mInt));
+          category = Some(unsigned(e.Get().u.mInt));
           e.Next();
         }
 
-        stack = aUniqueStacks.AppendFrame(stack, frameKey);
+        stack = aUniqueStacks.AppendFrame(
+          stack, UniqueStacks::FrameKey(strbuf.get(), line, category));
 
       } else if (e.Get().IsJitReturnAddr()) {
         numFrames++;
 
         // We can only process JitReturnAddr entries if we have a JSContext.
         MOZ_RELEASE_ASSERT(aContext);
 
         // A JIT frame may expand to multiple frames due to inlining.
--- a/tools/profiler/core/ProfileBufferEntry.h
+++ b/tools/profiler/core/ProfileBufferEntry.h
@@ -165,55 +165,43 @@ public:
     bool operator==(const JITAddress& aRhs) const
     {
       return mAddress == aRhs.mAddress && mStreamingGen == aRhs.mStreamingGen;
     }
     bool operator!=(const JITAddress& aRhs) const { return !(*this == aRhs); }
   };
 
   struct FrameKey {
-    // This cannot be a std::string, as it is not memmove compatible, which
-    // is used by nsHashTable
-    nsCString mLocation;
-    mozilla::Maybe<unsigned> mLine;
-    mozilla::Maybe<unsigned> mCategory;
-    mozilla::Maybe<JITAddress> mJITAddress;
-    mozilla::Maybe<uint32_t> mJITDepth;
+    const nsCString mLocation;
+    const mozilla::Maybe<unsigned> mLine;
+    const mozilla::Maybe<unsigned> mCategory;
+    const mozilla::Maybe<JITAddress> mJITAddress;
+    const mozilla::Maybe<uint32_t> mJITDepth;
 
     explicit FrameKey(const char* aLocation)
-     : mLocation(aLocation)
-    {
-      mHash = Hash();
-    }
+      : mLocation(aLocation)
+    {}
 
-    FrameKey(const FrameKey& aToCopy)
-     : mLocation(aToCopy.mLocation)
-     , mLine(aToCopy.mLine)
-     , mCategory(aToCopy.mCategory)
-     , mJITAddress(aToCopy.mJITAddress)
-     , mJITDepth(aToCopy.mJITDepth)
-    {
-      mHash = Hash();
-    }
+    FrameKey(const char* aLocation, const mozilla::Maybe<unsigned>& aLine,
+             const mozilla::Maybe<unsigned>& aCategory)
+      : mLocation(aLocation)
+      , mLine(aLine)
+      , mCategory(aCategory)
+    {}
 
     FrameKey(const JITAddress& aJITAddress, uint32_t aJITDepth)
      : mJITAddress(mozilla::Some(aJITAddress))
      , mJITDepth(mozilla::Some(aJITDepth))
-    {
-      mHash = Hash();
-    }
+    {}
+
+    FrameKey(const FrameKey& aOther) = default;
 
     uint32_t Hash() const;
     bool operator==(const FrameKey& aOther) const;
-    bool operator<(const FrameKey& aOther) const {
-      return mHash < aOther.mHash;
-    }
-
-  private:
-    uint32_t mHash;
+    bool operator!=(const FrameKey& aOther) const { return !(*this == aOther); }
   };
 
   struct StackKey {
     mozilla::Maybe<uint32_t> mPrefixStackIndex;
     uint32_t mFrameIndex;
 
     explicit StackKey(uint32_t aFrame)
      : mFrameIndex(aFrame)