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