Bug 1371956 - Use mApproximatelyVisibleFrames.EnsureInserted/EnsureRemoved to avoid doing unnecessary hashtable lookups. r=froydnj

MozReview-Commit-ID: 87A0v0APtFs
This commit is contained in:
Mats Palmgren 2017-06-17 00:06:04 +02:00
Родитель 41a0eaaaa9
Коммит 7648c5aafb
1 изменённых файлов: 6 добавлений и 14 удалений

Просмотреть файл

@ -5768,10 +5768,8 @@ PresShell::MarkFramesInListApproximatelyVisible(const nsDisplayList& aList,
// Use the presshell containing the frame. // Use the presshell containing the frame.
auto* presShell = static_cast<PresShell*>(frame->PresContext()->PresShell()); auto* presShell = static_cast<PresShell*>(frame->PresContext()->PresShell());
uint32_t count = presShell->mApproximatelyVisibleFrames.Count();
MOZ_ASSERT(!presShell->AssumeAllFramesVisible()); MOZ_ASSERT(!presShell->AssumeAllFramesVisible());
presShell->mApproximatelyVisibleFrames.PutEntry(frame); if (presShell->mApproximatelyVisibleFrames.EnsureInserted(frame)) {
if (presShell->mApproximatelyVisibleFrames.Count() > count) {
// The frame was added to mApproximatelyVisibleFrames, so increment its visible count. // The frame was added to mApproximatelyVisibleFrames, so increment its visible count.
frame->IncApproximateVisibleCount(); frame->IncApproximateVisibleCount();
} }
@ -5909,9 +5907,7 @@ PresShell::MarkFramesInSubtreeApproximatelyVisible(nsIFrame* aFrame,
aFrame->StyleVisibility()->IsVisible() && aFrame->StyleVisibility()->IsVisible() &&
(!aRemoveOnly || aFrame->GetVisibility() == Visibility::APPROXIMATELY_VISIBLE)) { (!aRemoveOnly || aFrame->GetVisibility() == Visibility::APPROXIMATELY_VISIBLE)) {
MOZ_ASSERT(!AssumeAllFramesVisible()); MOZ_ASSERT(!AssumeAllFramesVisible());
uint32_t count = mApproximatelyVisibleFrames.Count(); if (mApproximatelyVisibleFrames.EnsureInserted(aFrame)) {
mApproximatelyVisibleFrames.PutEntry(aFrame);
if (mApproximatelyVisibleFrames.Count() > count) {
// The frame was added to mApproximatelyVisibleFrames, so increment its visible count. // The frame was added to mApproximatelyVisibleFrames, so increment its visible count.
aFrame->IncApproximateVisibleCount(); aFrame->IncApproximateVisibleCount();
} }
@ -6233,9 +6229,8 @@ PresShell::EnsureFrameInApproximatelyVisibleList(nsIFrame* aFrame)
} }
#endif #endif
if (!mApproximatelyVisibleFrames.Contains(aFrame)) { if (mApproximatelyVisibleFrames.EnsureInserted(aFrame)) {
MOZ_ASSERT(!AssumeAllFramesVisible()); // We inserted a new entry.
mApproximatelyVisibleFrames.PutEntry(aFrame);
aFrame->IncApproximateVisibleCount(); aFrame->IncApproximateVisibleCount();
} }
} }
@ -6258,11 +6253,8 @@ PresShell::RemoveFrameFromApproximatelyVisibleList(nsIFrame* aFrame)
return; return;
} }
uint32_t count = mApproximatelyVisibleFrames.Count(); if (mApproximatelyVisibleFrames.EnsureRemoved(aFrame) &&
mApproximatelyVisibleFrames.RemoveEntry(aFrame); aFrame->TrackingVisibility()) {
if (aFrame->TrackingVisibility() &&
mApproximatelyVisibleFrames.Count() < count) {
// aFrame was in the hashtable, and we're still tracking its visibility, // aFrame was in the hashtable, and we're still tracking its visibility,
// so we need to decrement its visible count. // so we need to decrement its visible count.
aFrame->DecApproximateVisibleCount(); aFrame->DecApproximateVisibleCount();