summaryrefslogtreecommitdiff
path: root/layout/base
diff options
context:
space:
mode:
authorwin7-7 <win7-7@users.noreply.github.com>2022-04-18 13:15:28 +0300
committerwin7-7 <win7-7@users.noreply.github.com>2022-04-18 13:15:28 +0300
commit5b84c3e982140280c00ab697d7fcad519a7a71a1 (patch)
tree85d184a9cd3747af702d75ec60c23f1d19b459da /layout/base
parentd347a1e0c6f921f88ddb596379aea26bf1bf5144 (diff)
parent3abcec5d8bc1e4b420ef4b8a2e4b96433d67e2c7 (diff)
downloaduxp-5b84c3e982140280c00ab697d7fcad519a7a71a1.tar.gz
Merge branch 'master' into pr-1860
Diffstat (limited to 'layout/base')
-rw-r--r--layout/base/nsGenConList.cpp11
-rw-r--r--layout/base/nsGenConList.h6
2 files changed, 16 insertions, 1 deletions
diff --git a/layout/base/nsGenConList.cpp b/layout/base/nsGenConList.cpp
index bdb47e1838..fb0733f2e7 100644
--- a/layout/base/nsGenConList.cpp
+++ b/layout/base/nsGenConList.cpp
@@ -19,6 +19,7 @@ nsGenConList::Clear()
delete node;
}
mSize = 0;
+ mLastInserted = nullptr;
}
bool
@@ -41,6 +42,9 @@ nsGenConList::DestroyNodesFor(nsIFrame* aFrame)
node = nextNode;
}
+ // Modification of the list invalidates the cached pointer.
+ mLastInserted = nullptr;
+
return true;
}
@@ -108,6 +112,11 @@ nsGenConList::Insert(nsGenConNode* aNode)
// Check for append.
if (mList.isEmpty() || NodeAfter(aNode, mList.getLast())) {
mList.insertBack(aNode);
+ } else if (mLastInserted && mLastInserted != mList.getLast() &&
+ NodeAfter(aNode, mLastInserted) &&
+ NodeAfter(Next(mLastInserted), aNode)) {
+ // Fast path for inserting many consecutive nodes in one place
+ mLastInserted->setNext(aNode);
} else {
// Binary search.
@@ -142,6 +151,8 @@ nsGenConList::Insert(nsGenConNode* aNode)
}
++mSize;
+ mLastInserted = aNode;
+
// Set the mapping only if it is the first node of the frame.
// The DEBUG blocks below are for ensuring the invariant required by
// nsGenConList::DestroyNodesFor. See comment there.
diff --git a/layout/base/nsGenConList.h b/layout/base/nsGenConList.h
index 55bf6bc32e..58421d4301 100644
--- a/layout/base/nsGenConList.h
+++ b/layout/base/nsGenConList.h
@@ -86,7 +86,7 @@ protected:
uint32_t mSize;
public:
- nsGenConList() : mSize(0) {}
+ nsGenConList() : mSize(0), mLastInserted(nullptr) {}
~nsGenConList() { Clear(); }
void Clear();
static nsGenConNode* Next(nsGenConNode* aNode) {
@@ -127,6 +127,10 @@ private:
// Map from frame to the first nsGenConNode of it in the list.
nsDataHashtable<nsPtrHashKey<nsIFrame>, nsGenConNode*> mNodes;
+
+ // A weak pointer to the node most recently inserted, used to avoid repeated
+ // list traversals in Insert().
+ nsGenConNode* mLastInserted;
};
#endif /* nsGenConList_h___ */