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