Bug 1144820 - Use nsTArray<UniquePtr<>> to hold timeline markers. r=smaug, r=fitzgen

This commit is contained in:
Tom Tromey 2015-03-27 08:42:00 -04:00
parent 018eebcd63
commit 785556f6f3
4 changed files with 11 additions and 15 deletions

View File

@ -33,9 +33,9 @@ public:
// Check whether two markers should be considered the same, // Check whether two markers should be considered the same,
// for the purpose of pairing start and end markers. Normally // for the purpose of pairing start and end markers. Normally
// this definition suffices. // this definition suffices.
virtual bool Equals(const TimelineMarker* aOther) virtual bool Equals(const TimelineMarker& aOther)
{ {
return strcmp(mName, aOther->mName) == 0; return strcmp(mName, aOther.mName) == 0;
} }
// Add details specific to this marker type to aMarker. The // Add details specific to this marker type to aMarker. The

View File

@ -2977,10 +2977,10 @@ nsDocShell::PopProfileTimelineMarkers(
// If we see an unpaired START, we keep it around for the next call // If we see an unpaired START, we keep it around for the next call
// to PopProfileTimelineMarkers. We store the kept START objects in // to PopProfileTimelineMarkers. We store the kept START objects in
// this array. // this array.
nsTArray<TimelineMarker*> keptMarkers; nsTArray<UniquePtr<TimelineMarker>> keptMarkers;
for (uint32_t i = 0; i < mProfileTimelineMarkers.Length(); ++i) { for (uint32_t i = 0; i < mProfileTimelineMarkers.Length(); ++i) {
TimelineMarker* startPayload = mProfileTimelineMarkers[i]; UniquePtr<TimelineMarker>& startPayload = mProfileTimelineMarkers[i];
const char* startMarkerName = startPayload->GetName(); const char* startMarkerName = startPayload->GetName();
bool hasSeenPaintedLayer = false; bool hasSeenPaintedLayer = false;
@ -3002,7 +3002,7 @@ nsDocShell::PopProfileTimelineMarkers(
// enough for the amount of markers to always be small enough that the // enough for the amount of markers to always be small enough that the
// nested for loop isn't going to be a performance problem. // nested for loop isn't going to be a performance problem.
for (uint32_t j = i + 1; j < mProfileTimelineMarkers.Length(); ++j) { for (uint32_t j = i + 1; j < mProfileTimelineMarkers.Length(); ++j) {
TimelineMarker* endPayload = mProfileTimelineMarkers[j]; UniquePtr<TimelineMarker>& endPayload = mProfileTimelineMarkers[j];
const char* endMarkerName = endPayload->GetName(); const char* endMarkerName = endPayload->GetName();
// Look for Layer markers to stream out paint markers. // Look for Layer markers to stream out paint markers.
@ -3011,7 +3011,7 @@ nsDocShell::PopProfileTimelineMarkers(
endPayload->AddLayerRectangles(layerRectangles); endPayload->AddLayerRectangles(layerRectangles);
} }
if (!startPayload->Equals(endPayload)) { if (!startPayload->Equals(*endPayload)) {
continue; continue;
} }
@ -3048,14 +3048,13 @@ nsDocShell::PopProfileTimelineMarkers(
// If we did not see the corresponding END, keep the START. // If we did not see the corresponding END, keep the START.
if (!hasSeenEnd) { if (!hasSeenEnd) {
keptMarkers.AppendElement(mProfileTimelineMarkers[i]); keptMarkers.AppendElement(Move(mProfileTimelineMarkers[i]));
mProfileTimelineMarkers.RemoveElementAt(i); mProfileTimelineMarkers.RemoveElementAt(i);
--i; --i;
} }
} }
} }
ClearProfileTimelineMarkers();
mProfileTimelineMarkers.SwapElements(keptMarkers); mProfileTimelineMarkers.SwapElements(keptMarkers);
if (!ToJSValue(aCx, profileTimelineMarkers, aProfileTimelineMarkers)) { if (!ToJSValue(aCx, profileTimelineMarkers, aProfileTimelineMarkers)) {
@ -3089,7 +3088,7 @@ void
nsDocShell::AddProfileTimelineMarker(UniquePtr<TimelineMarker>&& aMarker) nsDocShell::AddProfileTimelineMarker(UniquePtr<TimelineMarker>&& aMarker)
{ {
if (mProfileTimelineRecording) { if (mProfileTimelineRecording) {
mProfileTimelineMarkers.AppendElement(aMarker.release()); mProfileTimelineMarkers.AppendElement(Move(aMarker));
} }
} }
@ -3125,9 +3124,6 @@ nsDocShell::GetWindowDraggingAllowed(bool* aValue)
void void
nsDocShell::ClearProfileTimelineMarkers() nsDocShell::ClearProfileTimelineMarkers()
{ {
for (uint32_t i = 0; i < mProfileTimelineMarkers.Length(); ++i) {
delete mProfileTimelineMarkers[i];
}
mProfileTimelineMarkers.Clear(); mProfileTimelineMarkers.Clear();
} }

View File

@ -984,7 +984,7 @@ private:
// True if recording profiles. // True if recording profiles.
bool mProfileTimelineRecording; bool mProfileTimelineRecording;
nsTArray<TimelineMarker*> mProfileTimelineMarkers; nsTArray<mozilla::UniquePtr<TimelineMarker>> mProfileTimelineMarkers;
// Get rid of all the timeline markers accumulated so far // Get rid of all the timeline markers accumulated so far
void ClearProfileTimelineMarkers(); void ClearProfileTimelineMarkers();

View File

@ -934,13 +934,13 @@ public:
} }
} }
virtual bool Equals(const TimelineMarker* aOther) override virtual bool Equals(const TimelineMarker& aOther) override
{ {
if (!TimelineMarker::Equals(aOther)) { if (!TimelineMarker::Equals(aOther)) {
return false; return false;
} }
// Console markers must have matching causes as well. // Console markers must have matching causes as well.
return GetCause() == aOther->GetCause(); return GetCause() == aOther.GetCause();
} }
virtual void AddDetails(mozilla::dom::ProfileTimelineMarker& aMarker) override virtual void AddDetails(mozilla::dom::ProfileTimelineMarker& aMarker) override