NodeInfoManager should use a local cache

issue #1111
This commit is contained in:
win7-7 2019-05-25 16:22:19 +03:00 committed by Roy Tam
commit 53acd97766
2 changed files with 32 additions and 2 deletions

View file

@ -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