From ac24e852fff8a649b8a5006f04e0feec2cca6978 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Tue, 9 Jul 2002 07:10:41 +0000 Subject: [PATCH] add an additional one-slot global content list cache. Bug 140758 stuff again, patch by jst@netscape.com, r=bzbarsky, sr=rbs git-svn-id: svn://10.0.0.236/trunk@124834 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsContentList.cpp | 25 +++++++++++++++++++++- mozilla/content/base/src/nsContentList.h | 2 ++ mozilla/content/build/nsContentModule.cpp | 2 ++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/mozilla/content/base/src/nsContentList.cpp b/mozilla/content/base/src/nsContentList.cpp index 711d1bd7ad1..41a852c3820 100644 --- a/mozilla/content/base/src/nsContentList.cpp +++ b/mozilla/content/base/src/nsContentList.cpp @@ -55,6 +55,9 @@ #include "pldhash.h" + +static nsIContentList *gCachedContentList; + nsBaseContentList::nsBaseContentList() { NS_INIT_REFCNT(); @@ -135,6 +138,14 @@ nsBaseContentList::Reset() return NS_OK; } +// static +void +nsBaseContentList::Shutdown() +{ + NS_IF_RELEASE(gCachedContentList); +} + + // nsFormContentList // This helper function checks if aContent is in some way associated @@ -375,7 +386,19 @@ NS_GetContentList(nsIDocument* aDocument, nsIAtom* aMatchAtom, *aInstancePtrResult = list; NS_ADDREF(*aInstancePtrResult); - + + // Hold on to the last requested content list to avoid having it be + // removed from the cache immediately when it's released. Avoid + // bumping the refcount on the list if the requested list is the one + // that's already cached. + + if (gCachedContentList != list) { + NS_IF_RELEASE(gCachedContentList); + + gCachedContentList = list; + NS_ADDREF(gCachedContentList); + } + return NS_OK; } diff --git a/mozilla/content/base/src/nsContentList.h b/mozilla/content/base/src/nsContentList.h index 0a29880d60a..aa7a86359a5 100644 --- a/mozilla/content/base/src/nsContentList.h +++ b/mozilla/content/base/src/nsContentList.h @@ -69,6 +69,8 @@ public: NS_IMETHOD IndexOf(nsIContent *aContent, PRInt32& aIndex); NS_IMETHOD Reset(); + static void Shutdown(); + protected: nsAutoVoidArray mElements; }; diff --git a/mozilla/content/build/nsContentModule.cpp b/mozilla/content/build/nsContentModule.cpp index 0687974c45f..aaa1925465b 100644 --- a/mozilla/content/build/nsContentModule.cpp +++ b/mozilla/content/build/nsContentModule.cpp @@ -107,6 +107,7 @@ #include "nsRuleNode.h" #include "nsWyciwygProtocolHandler.h" #include "nsContentAreaDragDrop.h" +#include "nsContentList.h" class nsIDocumentLoaderFactory; @@ -233,6 +234,7 @@ Shutdown(nsIModule* aSelf) nsGenericElement::Shutdown(); nsGenericDOMDataNode::Shutdown(); nsEventListenerManager::Shutdown(); + nsContentList::Shutdown(); nsComputedDOMStyle::Shutdown(); // Release all of our atoms