Bug 1196430 - part 2 - give SerialNumberRecord a proper constructor; r=mccr8
authorNathan Froyd <froydnj@mozilla.com>
Wed, 26 Aug 2015 18:25:35 -0400
changeset 296106 884124b5b4d8acff2d413e3cef8d3ecee840bef5
parent 296105 ae7368db9b083aa05aadd1efafb1dbdbedcd3882
child 296107 f7734f2e5b0ce89339beda1a651b596cb9edc287
push id962
push userjlund@mozilla.com
push dateFri, 04 Dec 2015 23:28:54 +0000
treeherdermozilla-release@23a2d286e80f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1196430
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1196430 - part 2 - give SerialNumberRecord a proper constructor; r=mccr8 Using C++ style is so much nicer for these sorts of things. This change also paves the way for easily using non-POD things in SerialNumberRecord.
xpcom/base/nsTraceRefcnt.cpp
--- a/xpcom/base/nsTraceRefcnt.cpp
+++ b/xpcom/base/nsTraceRefcnt.cpp
@@ -106,16 +106,22 @@ static nsrefcnt gInitCount;
 
 static FILE* gBloatLog = nullptr;
 static FILE* gRefcntsLog = nullptr;
 static FILE* gAllocLog = nullptr;
 static FILE* gCOMPtrLog = nullptr;
 
 struct SerialNumberRecord
 {
+  SerialNumberRecord()
+    : serialNumber(++gNextSerialNumber)
+    , refCount(0)
+    , COMPtrCount(0)
+  {}
+
   intptr_t serialNumber;
   int32_t refCount;
   int32_t COMPtrCount;
 };
 
 struct nsTraceRefcntStats
 {
   uint64_t mCreates;
@@ -182,17 +188,17 @@ DefaultAllocEntry(void* aPool, const voi
 {
   return PR_NEW(PLHashEntry);
 }
 
 static void
 SerialNumberFreeEntry(void* aPool, PLHashEntry* aHashEntry, unsigned aFlag)
 {
   if (aFlag == HT_FREE_ENTRY) {
-    PR_Free(reinterpret_cast<SerialNumberRecord*>(aHashEntry->value));
+    delete reinterpret_cast<SerialNumberRecord*>(aHashEntry->value);
     PR_Free(aHashEntry);
   }
 }
 
 static void
 TypesToLogFreeEntry(void* aPool, PLHashEntry* aHashEntry, unsigned aFlag)
 {
   if (aFlag == HT_FREE_ENTRY) {
@@ -576,20 +582,17 @@ static intptr_t
 GetSerialNumber(void* aPtr, bool aCreate)
 {
   PLHashEntry** hep = PL_HashTableRawLookup(gSerialNumbers,
                                             HashNumber(aPtr),
                                             aPtr);
   if (hep && *hep) {
     return reinterpret_cast<SerialNumberRecord*>((*hep)->value)->serialNumber;
   } else if (aCreate) {
-    SerialNumberRecord* record = PR_NEW(SerialNumberRecord);
-    record->serialNumber = ++gNextSerialNumber;
-    record->refCount = 0;
-    record->COMPtrCount = 0;
+    SerialNumberRecord* record = new SerialNumberRecord();
     PL_HashTableRawAdd(gSerialNumbers, hep, HashNumber(aPtr),
                        aPtr, reinterpret_cast<void*>(record));
     return gNextSerialNumber;
   }
   return 0;
 }
 
 static int32_t*