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,
// for the purpose of pairing start and end markers. Normally
// 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

View File

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

View File

@ -984,7 +984,7 @@ private:
// True if recording profiles.
bool mProfileTimelineRecording;
nsTArray<TimelineMarker*> mProfileTimelineMarkers;
nsTArray<mozilla::UniquePtr<TimelineMarker>> mProfileTimelineMarkers;
// Get rid of all the timeline markers accumulated so far
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)) {
return false;
}
// Console markers must have matching causes as well.
return GetCause() == aOther->GetCause();
return GetCause() == aOther.GetCause();
}
virtual void AddDetails(mozilla::dom::ProfileTimelineMarker& aMarker) override