Bug 659539 Part 5: Speed up nsINodeInfo::GetDocument by caching the nodeinfo managers mDocument pointer. r=bz

This commit is contained in:
Jonas Sicking 2011-06-14 17:58:57 -07:00
parent 9d5d1f3219
commit 3ff01744c1
4 changed files with 17 additions and 1 deletions

View File

@ -309,7 +309,7 @@ public:
*/
nsIDocument* GetDocument() const
{
return mOwnerManager->GetDocument();
return mDocument;
}
protected:
@ -359,6 +359,8 @@ protected:
// nsNodeInfoManager needs to pass mInner to the hash table.
friend class nsNodeInfoManager;
nsIDocument* mDocument; // Weak. Cache of mOwnerManager->mDocument
nsNodeInfoInner mInner;
nsCOMPtr<nsIAtom> mIDAttributeAtom;

View File

@ -120,6 +120,8 @@ nsNodeInfo::nsNodeInfo(nsIAtom *aName, nsIAtom *aPrefix, PRInt32 aNamespaceID,
NS_ADDREF(mOwnerManager = aOwnerManager);
NS_IF_ADDREF(mInner.mExtraName = aExtraName);
mDocument = aOwnerManager->GetDocument();
// Now compute our cached members.
// Qualified name. If we have no prefix, use ToString on

View File

@ -194,6 +194,14 @@ nsNodeInfoManager::Init(nsIDocument *aDocument)
return NS_OK;
}
// static
PRIntn
nsNodeInfoManager::DropNodeInfoDocument(PLHashEntry *he, PRIntn hashIndex, void *arg)
{
static_cast<nsINodeInfo*>(he->value)->mDocument = nsnull;
return HT_ENUMERATE_NEXT;
}
void
nsNodeInfoManager::DropDocumentReference()
{
@ -201,6 +209,8 @@ nsNodeInfoManager::DropDocumentReference()
mBindingManager->DropDocumentReference();
}
PL_HashTableEnumerateEntries(mNodeInfoHash, DropNodeInfoDocument, nsnull);
mDocument = nsnull;
}

View File

@ -153,6 +153,8 @@ protected:
private:
static PRIntn NodeInfoInnerKeyCompare(const void *key1, const void *key2);
static PLHashNumber GetNodeInfoInnerHashValue(const void *key);
static PRIntn DropNodeInfoDocument(PLHashEntry *he, PRIntn hashIndex,
void *arg);
PLHashTable *mNodeInfoHash;
nsIDocument *mDocument; // WEAK