summaryrefslogtreecommitdiffstats
path: root/dom
diff options
context:
space:
mode:
authorMoonchild <git-repo@palemoon.org>2019-05-25 15:57:54 +0000
committerGitHub <noreply@github.com>2019-05-25 15:57:54 +0000
commit02b10f4bd78c4082d50dd03ea8854b0d1a27b48e (patch)
tree45f258762ebb4a71380d6d6225320bef1ae76e0a /dom
parent1f239f8179bce5df201ec486519efbda9d50861b (diff)
parent449cb277d4dd0cd6269a5874629fd9a5c36db3a3 (diff)
downloadUXP-02b10f4bd78c4082d50dd03ea8854b0d1a27b48e.tar
UXP-02b10f4bd78c4082d50dd03ea8854b0d1a27b48e.tar.gz
UXP-02b10f4bd78c4082d50dd03ea8854b0d1a27b48e.tar.lz
UXP-02b10f4bd78c4082d50dd03ea8854b0d1a27b48e.tar.xz
UXP-02b10f4bd78c4082d50dd03ea8854b0d1a27b48e.zip
Merge pull request #1119 from win7-7/NodeInfoManager-local-cache
NodeInfoManager should use a local cache
Diffstat (limited to 'dom')
-rw-r--r--dom/base/nsNodeInfoManager.cpp31
-rw-r--r--dom/base/nsNodeInfoManager.h3
2 files changed, 32 insertions, 2 deletions
diff --git a/dom/base/nsNodeInfoManager.cpp b/dom/base/nsNodeInfoManager.cpp
index 985d540b4..1f751ea71 100644
--- a/dom/base/nsNodeInfoManager.cpp
+++ b/dom/base/nsNodeInfoManager.cpp
@@ -112,7 +112,8 @@ nsNodeInfoManager::nsNodeInfoManager()
mNonDocumentNodeInfos(0),
mTextNodeInfo(nullptr),
mCommentNodeInfo(nullptr),
- mDocumentNodeInfo(nullptr)
+ mDocumentNodeInfo(nullptr),
+ mRecentlyUsedNodeInfos{}
{
nsLayoutStatics::AddRef();
@@ -232,11 +233,19 @@ nsNodeInfoManager::GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix,
NodeInfo::NodeInfoInner tmpKey(aName, aPrefix, aNamespaceID, aNodeType,
aExtraName);
+ uint32_t index =
+ GetNodeInfoInnerHashValue(&tmpKey) % RECENTLY_USED_NODEINFOS_SIZE;
+ NodeInfo* ni = mRecentlyUsedNodeInfos[index];
+ if (ni && NodeInfoInnerKeyCompare(&(ni->mInner), &tmpKey)) {
+ RefPtr<NodeInfo> nodeInfo = ni;
+ return nodeInfo.forget();
+ }
+
void *node = PL_HashTableLookup(mNodeInfoHash, &tmpKey);
if (node) {
RefPtr<NodeInfo> nodeInfo = static_cast<NodeInfo*>(node);
-
+ mRecentlyUsedNodeInfos[index] = nodeInfo;
return nodeInfo.forget();
}
@@ -254,6 +263,7 @@ nsNodeInfoManager::GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix,
NS_IF_ADDREF(mDocument);
}
+ mRecentlyUsedNodeInfos[index] = newNodeInfo;
return newNodeInfo.forget();
}
@@ -272,10 +282,20 @@ nsNodeInfoManager::GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
NodeInfo::NodeInfoInner tmpKey(aName, aPrefix, aNamespaceID, aNodeType);
+ uint32_t index =
+ GetNodeInfoInnerHashValue(&tmpKey) % RECENTLY_USED_NODEINFOS_SIZE;
+ NodeInfo* ni = mRecentlyUsedNodeInfos[index];
+ if (ni && NodeInfoInnerKeyCompare(&(ni->mInner), &tmpKey)) {
+ RefPtr<NodeInfo> nodeInfo = ni;
+ nodeInfo.forget(aNodeInfo);
+ return NS_OK;
+ }
+
void *node = PL_HashTableLookup(mNodeInfoHash, &tmpKey);
if (node) {
RefPtr<NodeInfo> nodeInfo = static_cast<NodeInfo*>(node);
+ mRecentlyUsedNodeInfos[index] = nodeInfo;
nodeInfo.forget(aNodeInfo);
return NS_OK;
@@ -297,6 +317,7 @@ nsNodeInfoManager::GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
NS_IF_ADDREF(mDocument);
}
+ mRecentlyUsedNodeInfos[index] = newNodeInfo;
newNodeInfo.forget(aNodeInfo);
return NS_OK;
@@ -421,6 +442,12 @@ nsNodeInfoManager::RemoveNodeInfo(NodeInfo *aNodeInfo)
}
}
+ uint32_t index =
+ GetNodeInfoInnerHashValue(&aNodeInfo->mInner) % RECENTLY_USED_NODEINFOS_SIZE;
+ if (mRecentlyUsedNodeInfos[index] == aNodeInfo) {
+ mRecentlyUsedNodeInfos[index] = nullptr;
+ }
+
#ifdef DEBUG
bool ret =
#endif
diff --git a/dom/base/nsNodeInfoManager.h b/dom/base/nsNodeInfoManager.h
index 6ece66577..759dd391e 100644
--- a/dom/base/nsNodeInfoManager.h
+++ b/dom/base/nsNodeInfoManager.h
@@ -32,6 +32,8 @@ class NodeInfo;
} // namespace dom
} // namespace mozilla
+#define RECENTLY_USED_NODEINFOS_SIZE 31
+
class nsNodeInfoManager final
{
private:
@@ -137,6 +139,7 @@ private:
mozilla::dom::NodeInfo * MOZ_NON_OWNING_REF mCommentNodeInfo; // WEAK to avoid circular ownership
mozilla::dom::NodeInfo * MOZ_NON_OWNING_REF mDocumentNodeInfo; // WEAK to avoid circular ownership
RefPtr<nsBindingManager> mBindingManager;
+ mozilla::dom::NodeInfo* mRecentlyUsedNodeInfos[RECENTLY_USED_NODEINFOS_SIZE];
};
#endif /* nsNodeInfoManager_h___ */