Skip to content
Snippets Groups Projects
Commit b12ec7f6 authored by Timothy Nikkel's avatar Timothy Nikkel
Browse files

Bug 1754435. Add a simple cache for nsDeckFrame::GetSelectedBox. r=emilio

It's easy to do and stops us from being wasteful.

Differential Revision: https://phabricator.services.mozilla.com/D138289
parent ad1af013
No related branches found
No related tags found
No related merge requests found
......@@ -49,7 +49,7 @@ NS_QUERYFRAME_HEAD(nsDeckFrame)
NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
nsDeckFrame::nsDeckFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
: nsBoxFrame(aStyle, aPresContext, kClassID), mIndex(0) {
: nsBoxFrame(aStyle, aPresContext, kClassID) {
nsCOMPtr<nsBoxLayout> layout;
NS_NewStackLayout(layout);
SetXULLayoutManager(layout);
......@@ -96,6 +96,8 @@ void nsDeckFrame::IndexChanged() {
if (currentBox) // only hide if it exists
HideBox(currentBox);
mSelectedBoxCache = nullptr;
mIndex = index;
ShowBox(GetSelectedBox());
......@@ -134,7 +136,10 @@ int32_t nsDeckFrame::GetSelectedIndex() {
}
nsIFrame* nsDeckFrame::GetSelectedBox() {
return (mIndex >= 0) ? mFrames.FrameAt(mIndex) : nullptr;
if (!mSelectedBoxCache && mIndex >= 0) {
mSelectedBoxCache = (mIndex >= 0) ? mFrames.FrameAt(mIndex) : nullptr;
}
return mSelectedBoxCache;
}
void nsDeckFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
......@@ -148,6 +153,10 @@ void nsDeckFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
void nsDeckFrame::RemoveFrame(ChildListID aListID, nsIFrame* aOldFrame) {
nsIFrame* currentFrame = GetSelectedBox();
if (aOldFrame == currentFrame) {
mSelectedBoxCache = nullptr;
}
if (currentFrame && aOldFrame && currentFrame != aOldFrame) {
// If the frame we're removing is at an index that's less
// than mIndex, that means we're going to be shifting indexes
......@@ -159,6 +168,10 @@ void nsDeckFrame::RemoveFrame(ChildListID aListID, nsIFrame* aOldFrame) {
MOZ_ASSERT(removedIndex >= 0,
"A deck child was removed that was not in mFrames.");
if (removedIndex < mIndex) {
// This shouldn't invalidate our cache, but be really paranoid, it's not
// that important to keep our cache here.
mSelectedBoxCache = nullptr;
mIndex--;
// This is going to cause us to handle the index change in IndexedChanged,
// but since the new index will match mIndex, it's essentially a noop.
......
......@@ -68,7 +68,8 @@ class nsDeckFrame final : public nsBoxFrame {
void ShowBox(nsIFrame* aBox);
private:
int32_t mIndex;
int32_t mIndex = 0;
nsIFrame* mSelectedBoxCache = nullptr;
void Animate(nsIFrame*, bool);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment