Bug 1167230 - Use nsCString instead of std::string in FrameKey in the profiler. (r=mstange)
authorShu-yu Guo <shu@rfrn.org>
Tue, 26 May 2015 22:58:40 -0700
changeset 268021 1118d069545209d920f317f508195e675ec4cfb4
parent 268020 588c920f963c444724feb1e575b8ff1af2ead106
child 268022 4e6c2d88d5f94b4f44c79800fa0b3f63f8542b81
push id2294
push userbsmedberg@mozilla.com
push dateWed, 27 May 2015 15:05:10 +0000
reviewersmstange
bugs1167230
milestone41.0a1
Bug 1167230 - Use nsCString instead of std::string in FrameKey in the profiler. (r=mstange)
tools/profiler/ProfileEntry.cpp
tools/profiler/ProfileEntry.h
--- a/tools/profiler/ProfileEntry.cpp
+++ b/tools/profiler/ProfileEntry.cpp
@@ -355,17 +355,20 @@ void UniqueStacks::Stack::AppendFrame(co
 
 uint32_t UniqueStacks::Stack::GetOrAddIndex() const
 {
   return mUniqueStacks.GetOrAddStackIndex(mStack);
 }
 
 uint32_t UniqueStacks::FrameKey::Hash() const
 {
-  uint32_t hash = mozilla::HashString(mLocation.c_str(), mLocation.length());
+  uint32_t hash = 0;
+  if (!mLocation.IsEmpty()) {
+    hash = mozilla::HashString(mLocation.get());
+  }
   if (mLine.isSome()) {
     hash = mozilla::AddToHash(hash, *mLine);
   }
   if (mCategory.isSome()) {
     hash = mozilla::AddToHash(hash, *mCategory);
   }
   if (mJITAddress.isSome()) {
     hash = mozilla::AddToHash(hash, *mJITAddress);
@@ -488,17 +491,17 @@ void UniqueStacks::StreamStack(const Sta
 
 void UniqueStacks::StreamFrame(const OnStackFrameKey& aFrame)
 {
   // Schema:
   //   [location, implementation, optimizations, line, category]
 
   mFrameTableWriter.StartArrayElement();
   if (!aFrame.mJITFrameHandle) {
-    mUniqueStrings.WriteElement(mFrameTableWriter, aFrame.mLocation.c_str());
+    mUniqueStrings.WriteElement(mFrameTableWriter, aFrame.mLocation.get());
     if (aFrame.mLine.isSome()) {
       mFrameTableWriter.NullElement(); // implementation
       mFrameTableWriter.NullElement(); // optimizations
       mFrameTableWriter.IntElement(*aFrame.mLine);
     }
     if (aFrame.mCategory.isSome()) {
       if (aFrame.mLine.isNothing()) {
         mFrameTableWriter.NullElement(); // line
--- a/tools/profiler/ProfileEntry.h
+++ b/tools/profiler/ProfileEntry.h
@@ -104,26 +104,34 @@ private:
   SpliceableChunkedJSONWriter mStringTableWriter;
   nsDataHashtable<nsCharPtrHashKey, uint32_t> mStringToIndexMap;
 };
 
 class UniqueStacks
 {
 public:
   struct FrameKey {
-    std::string mLocation;
+    nsCString mLocation;
     mozilla::Maybe<unsigned> mLine;
     mozilla::Maybe<unsigned> mCategory;
     mozilla::Maybe<void*> mJITAddress;
     mozilla::Maybe<uint32_t> mJITDepth;
 
     explicit FrameKey(const char* aLocation)
      : mLocation(aLocation)
     { }
 
+    FrameKey(const FrameKey& aToCopy)
+     : mLocation(aToCopy.mLocation)
+     , mLine(aToCopy.mLine)
+     , mCategory(aToCopy.mCategory)
+     , mJITAddress(aToCopy.mJITAddress)
+     , mJITDepth(aToCopy.mJITDepth)
+    { }
+
     FrameKey(void* aJITAddress, uint32_t aJITDepth)
      : mJITAddress(mozilla::Some(aJITAddress))
      , mJITDepth(mozilla::Some(aJITDepth))
     { }
 
     uint32_t Hash() const;
     bool operator==(const FrameKey& aOther) const;
   };
@@ -132,16 +140,21 @@ public:
   struct MOZ_STACK_CLASS OnStackFrameKey : public FrameKey {
     const JS::ForEachProfiledFrameOp::FrameHandle* mJITFrameHandle;
 
     explicit OnStackFrameKey(const char* aLocation)
       : FrameKey(aLocation)
       , mJITFrameHandle(nullptr)
     { }
 
+    OnStackFrameKey(const OnStackFrameKey& aToCopy)
+      : FrameKey(aToCopy)
+      , mJITFrameHandle(aToCopy.mJITFrameHandle)
+    { }
+
     OnStackFrameKey(void* aJITAddress, unsigned aJITDepth)
       : FrameKey(aJITAddress, aJITDepth)
       , mJITFrameHandle(nullptr)
     { }
 
     OnStackFrameKey(void* aJITAddress, unsigned aJITDepth,
                     const JS::ForEachProfiledFrameOp::FrameHandle& aJITFrameHandle)
       : FrameKey(aJITAddress, aJITDepth)