Bug 386769 - "Make setting innerHTML faster". r=jst, sr=peterv, a=blocking1.9.

git-svn-id: svn://10.0.0.236/trunk@245266 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
bent.mozilla%gmail.com 2008-02-08 22:07:53 +00:00
parent 67ad77f715
commit e21a2262ee
17 changed files with 235 additions and 65 deletions

View File

@ -941,6 +941,16 @@ public:
mJSObject = aJSObject; mJSObject = aJSObject;
} }
// This method should return an addrefed nsIParser* or nsnull. Implementations
// should transfer ownership of the parser to the caller.
virtual already_AddRefed<nsIParser> GetFragmentParser() {
return nsnull;
}
virtual void SetFragmentParser(nsIParser* aParser) {
// Do nothing.
}
protected: protected:
~nsIDocument() ~nsIDocument()
{ {

View File

@ -147,10 +147,17 @@ nsScriptLoaderObserverProxy::ScriptEvaluated(nsresult aResult,
} }
NS_IMPL_ISUPPORTS3(nsContentSink, NS_IMPL_CYCLE_COLLECTING_ADDREF(nsContentSink)
nsICSSLoaderObserver, NS_IMPL_CYCLE_COLLECTING_RELEASE(nsContentSink)
nsISupportsWeakReference,
nsIScriptLoaderObserver) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsContentSink)
NS_INTERFACE_MAP_ENTRY(nsICSSLoaderObserver)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY(nsIScriptLoaderObserver)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptLoaderObserver)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTION_2(nsContentSink, mDocument, mParser)
nsContentSink::nsContentSink() nsContentSink::nsContentSink()
{ {

View File

@ -62,6 +62,7 @@
#include "prlog.h" #include "prlog.h"
#include "nsIRequest.h" #include "nsIRequest.h"
#include "nsTimer.h" #include "nsTimer.h"
#include "nsCycleCollectionParticipant.h"
class nsIDocument; class nsIDocument;
class nsIURI; class nsIURI;
@ -114,7 +115,9 @@ class nsContentSink : public nsICSSLoaderObserver,
public nsStubDocumentObserver, public nsStubDocumentObserver,
public nsITimerCallback public nsITimerCallback
{ {
NS_DECL_ISUPPORTS NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsContentSink,
nsIScriptLoaderObserver)
NS_DECL_NSISCRIPTLOADEROBSERVER NS_DECL_NSISCRIPTLOADEROBSERVER
// nsITimerCallback // nsITimerCallback

View File

@ -78,6 +78,8 @@
#include "nsIParser.h" #include "nsIParser.h"
#include "nsIFragmentContentSink.h" #include "nsIFragmentContentSink.h"
#include "nsIContentSink.h" #include "nsIContentSink.h"
#include "nsIHTMLContentSink.h"
#include "nsIXMLContentSink.h"
#include "nsHTMLParts.h" #include "nsHTMLParts.h"
#include "nsIParserService.h" #include "nsIParserService.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
@ -130,7 +132,6 @@ static NS_DEFINE_CID(kXTFServiceCID, NS_XTFSERVICE_CID);
#include "nsIEventListenerManager.h" #include "nsIEventListenerManager.h"
#include "nsAttrName.h" #include "nsAttrName.h"
#include "nsIDOMUserDataHandler.h" #include "nsIDOMUserDataHandler.h"
#include "nsIFragmentContentSink.h"
#include "nsContentCreatorFunctions.h" #include "nsContentCreatorFunctions.h"
#include "nsTPtrArray.h" #include "nsTPtrArray.h"
#include "nsGUIEvent.h" #include "nsGUIEvent.h"
@ -3325,11 +3326,7 @@ nsContentUtils::CreateContextualFragment(nsIDOMNode* aContextNode,
NS_ENSURE_ARG(aContextNode); NS_ENSURE_ARG(aContextNode);
*aReturn = nsnull; *aReturn = nsnull;
// Create a new parser for this entire operation
nsresult rv; nsresult rv;
nsCOMPtr<nsIParser> parser = do_CreateInstance(kCParserCID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsINode> node = do_QueryInterface(aContextNode); nsCOMPtr<nsINode> node = do_QueryInterface(aContextNode);
NS_ENSURE_TRUE(node, NS_ERROR_NOT_AVAILABLE); NS_ENSURE_TRUE(node, NS_ERROR_NOT_AVAILABLE);
@ -3402,17 +3399,52 @@ nsContentUtils::CreateContextualFragment(nsIDOMNode* aContextNode,
nsCOMPtr<nsIHTMLDocument> htmlDoc(do_QueryInterface(document)); nsCOMPtr<nsIHTMLDocument> htmlDoc(do_QueryInterface(document));
PRBool bHTML = htmlDoc && !bCaseSensitive; PRBool bHTML = htmlDoc && !bCaseSensitive;
nsCOMPtr<nsIFragmentContentSink> sink;
if (bHTML) { // See if the document has a cached fragment parser. nsHTMLDocument is the
rv = NS_NewHTMLFragmentContentSink(getter_AddRefs(sink)); // only one that should really have one at the moment.
} else { nsCOMPtr<nsIParser> parser = document->GetFragmentParser();
rv = NS_NewXMLFragmentContentSink(getter_AddRefs(sink)); if (parser) {
// Get the parser ready to use.
parser->Reset();
}
else {
// Create a new parser for this operation.
parser = do_CreateInstance(kCParserCID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
}
// See if the parser already has a content sink that we can reuse.
nsCOMPtr<nsIFragmentContentSink> sink;
nsCOMPtr<nsIContentSink> contentsink = parser->GetContentSink();
if (contentsink) {
// Make sure it's the correct type.
if (bHTML) {
nsCOMPtr<nsIHTMLContentSink> htmlsink = do_QueryInterface(contentsink);
sink = do_QueryInterface(htmlsink);
}
else {
nsCOMPtr<nsIXMLContentSink> xmlsink = do_QueryInterface(contentsink);
sink = do_QueryInterface(xmlsink);
}
}
if (!sink) {
// Either there was no cached content sink or it was the wrong type. Make a
// new one.
if (bHTML) {
rv = NS_NewHTMLFragmentContentSink(getter_AddRefs(sink));
} else {
rv = NS_NewXMLFragmentContentSink(getter_AddRefs(sink));
}
NS_ENSURE_SUCCESS(rv, rv);
contentsink = do_QueryInterface(sink);
NS_ASSERTION(contentsink, "Sink doesn't QI to nsIContentSink!");
parser->SetContentSink(contentsink);
} }
NS_ENSURE_SUCCESS(rv, rv);
sink->SetTargetDocument(document); sink->SetTargetDocument(document);
nsCOMPtr<nsIContentSink> contentsink(do_QueryInterface(sink));
parser->SetContentSink(contentsink);
nsDTDMode mode = eDTDMode_autodetect; nsDTDMode mode = eDTDMode_autodetect;
switch (document->GetCompatibilityMode()) { switch (document->GetCompatibilityMode()) {
@ -3437,6 +3469,8 @@ nsContentUtils::CreateContextualFragment(nsIDOMNode* aContextNode,
rv = sink->GetFragment(aReturn); rv = sink->GetFragment(aReturn);
} }
document->SetFragmentParser(parser);
return NS_OK; return NS_OK;
} }

View File

@ -408,6 +408,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLDocument, nsDocument)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mEmbeds) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mEmbeds)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLinks) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLinks)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mAnchors) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mAnchors)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFragmentParser)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mForms, nsIDOMNodeList) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mForms, nsIDOMNodeList)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mFormControls, NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mFormControls,
nsIDOMNodeList) nsIDOMNodeList)

View File

@ -216,6 +216,13 @@ public:
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLDocument, nsDocument) NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLDocument, nsDocument)
virtual already_AddRefed<nsIParser> GetFragmentParser() {
return mFragmentParser.forget();
}
virtual void SetFragmentParser(nsIParser* aParser) {
mFragmentParser = aParser;
}
protected: protected:
nsresult GetBodySize(PRInt32* aWidth, nsresult GetBodySize(PRInt32* aWidth,
PRInt32* aHeight); PRInt32* aHeight);
@ -382,6 +389,9 @@ protected:
PRInt32 mDefaultNamespaceID; PRInt32 mDefaultNamespaceID;
PRBool mDisableCookieAccess; PRBool mDisableCookieAccess;
// Parser used for constructing document fragments.
nsCOMPtr<nsIParser> mFragmentParser;
}; };
#endif /* nsHTMLDocument_h___ */ #endif /* nsHTMLDocument_h___ */

View File

@ -64,6 +64,7 @@
#include "nsIScriptSecurityManager.h" #include "nsIScriptSecurityManager.h"
#include "nsContentSink.h" #include "nsContentSink.h"
#include "nsTHashtable.h" #include "nsTHashtable.h"
#include "nsCycleCollectionParticipant.h"
// //
// XXX THIS IS TEMPORARY CODE // XXX THIS IS TEMPORARY CODE
@ -79,7 +80,9 @@ public:
virtual ~nsHTMLFragmentContentSink(); virtual ~nsHTMLFragmentContentSink();
// nsISupports // nsISupports
NS_DECL_ISUPPORTS NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsHTMLFragmentContentSink,
nsIContentSink)
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
@ -223,12 +226,22 @@ nsHTMLFragmentContentSink::~nsHTMLFragmentContentSink()
} }
} }
NS_IMPL_ISUPPORTS3(nsHTMLFragmentContentSink, NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsHTMLFragmentContentSink,
nsIFragmentContentSink, nsIContentSink)
nsIHTMLContentSink, NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsHTMLFragmentContentSink,
nsIContentSink) nsIContentSink)
NS_IMETHODIMP NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsHTMLFragmentContentSink)
NS_INTERFACE_MAP_ENTRY(nsIFragmentContentSink)
NS_INTERFACE_MAP_ENTRY(nsIHTMLContentSink)
NS_INTERFACE_MAP_ENTRY(nsIContentSink)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContentSink)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTION_3(nsHTMLFragmentContentSink, mParser, mTargetDocument,
mRoot)
NS_IMETHODIMP
nsHTMLFragmentContentSink::WillBuildModel(void) nsHTMLFragmentContentSink::WillBuildModel(void)
{ {
if (mRoot) { if (mRoot) {

View File

@ -185,15 +185,30 @@ nsXMLContentSink::Init(nsIDocument* aDoc,
return NS_OK; return NS_OK;
} }
NS_IMPL_ISUPPORTS_INHERITED7(nsXMLContentSink, NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsXMLContentSink)
nsContentSink, NS_INTERFACE_MAP_ENTRY(nsIContentSink)
nsIContentSink, NS_INTERFACE_MAP_ENTRY(nsIXMLContentSink)
nsIXMLContentSink, NS_INTERFACE_MAP_ENTRY(nsIExpatSink)
nsIExpatSink, NS_INTERFACE_MAP_ENTRY(nsITimerCallback)
nsITimerCallback, NS_INTERFACE_MAP_ENTRY(nsIDocumentObserver)
nsIDocumentObserver, NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
nsIMutationObserver, NS_INTERFACE_MAP_ENTRY(nsITransformObserver)
nsITransformObserver) NS_INTERFACE_MAP_END_INHERITING(nsContentSink)
NS_IMPL_ADDREF_INHERITED(nsXMLContentSink, nsContentSink)
NS_IMPL_RELEASE_INHERITED(nsXMLContentSink, nsContentSink)
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXMLContentSink)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXMLContentSink,
nsContentSink)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCurrentHead)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mDocElement)
for (PRUint32 i = 0, count = tmp->mContentStack.Length(); i < count; i++) {
const StackNode& node = tmp->mContentStack.ElementAt(i);
cb.NoteXPCOMChild(node.mContent);
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
// nsIContentSink // nsIContentSink
NS_IMETHODIMP NS_IMETHODIMP

View File

@ -45,7 +45,7 @@
#include "nsTArray.h" #include "nsTArray.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "nsCycleCollectionParticipant.h"
class nsIDocument; class nsIDocument;
class nsIURI; class nsIURI;
@ -84,6 +84,9 @@ public:
// nsISupports // nsISupports
NS_DECL_ISUPPORTS_INHERITED NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsXMLContentSink,
nsContentSink)
NS_DECL_NSIEXPATSINK NS_DECL_NSIEXPATSINK
// nsIContentSink // nsIContentSink

View File

@ -60,6 +60,7 @@
#include "nsTHashtable.h" #include "nsTHashtable.h"
#include "nsHashKeys.h" #include "nsHashKeys.h"
#include "nsTArray.h" #include "nsTArray.h"
#include "nsCycleCollectionParticipant.h"
class nsXMLFragmentContentSink : public nsXMLContentSink, class nsXMLFragmentContentSink : public nsXMLContentSink,
public nsIFragmentContentSink public nsIFragmentContentSink
@ -72,6 +73,8 @@ public:
// nsISupports // nsISupports
NS_DECL_ISUPPORTS_INHERITED NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsXMLFragmentContentSink,
nsXMLContentSink)
// nsIExpatSink // nsIExpatSink
NS_IMETHOD HandleDoctypeDecl(const nsAString & aSubset, NS_IMETHOD HandleDoctypeDecl(const nsAString & aSubset,
@ -169,9 +172,20 @@ nsXMLFragmentContentSink::~nsXMLFragmentContentSink()
{ {
} }
NS_IMPL_ISUPPORTS_INHERITED1(nsXMLFragmentContentSink, NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsXMLFragmentContentSink)
nsXMLContentSink, NS_INTERFACE_MAP_ENTRY(nsIFragmentContentSink)
nsIFragmentContentSink) NS_INTERFACE_MAP_END_INHERITING(nsXMLContentSink)
NS_IMPL_ADDREF_INHERITED(nsXMLFragmentContentSink, nsXMLContentSink)
NS_IMPL_RELEASE_INHERITED(nsXMLFragmentContentSink, nsXMLContentSink)
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXMLFragmentContentSink)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXMLFragmentContentSink,
nsXMLContentSink)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTargetDocument)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRoot)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMETHODIMP NS_IMETHODIMP
nsXMLFragmentContentSink::WillBuildModel(void) nsXMLFragmentContentSink::WillBuildModel(void)

View File

@ -287,6 +287,8 @@ class nsIParser : public nsISupports {
*/ */
NS_IMETHOD CancelParsingEvents() = 0; NS_IMETHOD CancelParsingEvents() = 0;
virtual void Reset() = 0;
}; };
NS_DEFINE_STATIC_IID_ACCESSOR(nsIParser, NS_IPARSER_IID) NS_DEFINE_STATIC_IID_ACCESSOR(nsIParser, NS_IPARSER_IID)

View File

@ -113,11 +113,18 @@ static const char kInvalidTagStackPos[] = "Error: invalid tag stack position";
#define NS_DTD_FLAG_HAS_MAIN_CONTAINER (NS_DTD_FLAG_HAD_BODY | \ #define NS_DTD_FLAG_HAS_MAIN_CONTAINER (NS_DTD_FLAG_HAD_BODY | \
NS_DTD_FLAG_HAD_FRAMESET) NS_DTD_FLAG_HAD_FRAMESET)
NS_IMPL_ISUPPORTS1(CNavDTD, nsIDTD) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CNavDTD)
NS_INTERFACE_MAP_ENTRY(nsIDTD)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDTD)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(CNavDTD)
NS_IMPL_CYCLE_COLLECTING_RELEASE(CNavDTD)
NS_IMPL_CYCLE_COLLECTION_1(CNavDTD, mSink)
CNavDTD::CNavDTD() CNavDTD::CNavDTD()
: mMisplacedContent(0), : mMisplacedContent(0),
mSink(0),
mTokenAllocator(0), mTokenAllocator(0),
mBodyContext(new nsDTDContext()), mBodyContext(new nsDTDContext()),
mTempContext(0), mTempContext(0),
@ -181,8 +188,6 @@ CNavDTD::~CNavDTD()
} }
} }
#endif #endif
NS_IF_RELEASE(mSink);
} }
nsresult nsresult
@ -212,7 +217,7 @@ CNavDTD::WillBuildModel(const CParserContext& aParserContext,
START_TIMER(); START_TIMER();
if (NS_SUCCEEDED(result) && !mSink) { if (NS_SUCCEEDED(result) && !mSink) {
result = CallQueryInterface(aSink, &mSink); mSink = do_QueryInterface(aSink, &result);
if (NS_FAILED(result)) { if (NS_FAILED(result)) {
mFlags |= NS_DTD_FLAG_STOP_PARSING; mFlags |= NS_DTD_FLAG_STOP_PARSING;
return result; return result;

View File

@ -106,6 +106,7 @@
#include "nsTime.h" #include "nsTime.h"
#include "nsDTDUtils.h" #include "nsDTDUtils.h"
#include "nsParser.h" #include "nsParser.h"
#include "nsCycleCollectionParticipant.h"
class nsIHTMLContentSink; class nsIHTMLContentSink;
class nsIParserNode; class nsIParserNode;
@ -158,8 +159,9 @@ public:
eHTMLTags aTag, eHTMLTags aTag,
nsEntryStack* aStyleStack = nsnull); nsEntryStack* aStyleStack = nsnull);
NS_DECL_ISUPPORTS NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSIDTD NS_DECL_NSIDTD
NS_DECL_CYCLE_COLLECTION_CLASS(CNavDTD)
private: private:
/** /**
@ -381,7 +383,7 @@ protected:
nsDeque mMisplacedContent; nsDeque mMisplacedContent;
nsIHTMLContentSink* mSink; nsCOMPtr<nsIHTMLContentSink> mSink;
nsTokenAllocator* mTokenAllocator; nsTokenAllocator* mTokenAllocator;
nsDTDContext* mBodyContext; nsDTDContext* mBodyContext;
nsDTDContext* mTempContext; nsDTDContext* mTempContext;

View File

@ -378,9 +378,16 @@ IsLoadableDTD(const nsCatalogData* aCatalogData, nsIURI* aDTD,
/***************************** END CATALOG UTILS *****************************/ /***************************** END CATALOG UTILS *****************************/
NS_IMPL_ISUPPORTS2(nsExpatDriver, NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsExpatDriver)
nsITokenizer, NS_INTERFACE_MAP_ENTRY(nsITokenizer)
nsIDTD) NS_INTERFACE_MAP_ENTRY(nsIDTD)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDTD)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsExpatDriver)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsExpatDriver)
NS_IMPL_CYCLE_COLLECTION_2(nsExpatDriver, mSink, mExtendedSink)
nsExpatDriver::nsExpatDriver() nsExpatDriver::nsExpatDriver()
: mExpatParser(nsnull), : mExpatParser(nsnull),

View File

@ -46,6 +46,7 @@
#include "nsITokenizer.h" #include "nsITokenizer.h"
#include "nsIInputStream.h" #include "nsIInputStream.h"
#include "nsIParser.h" #include "nsIParser.h"
#include "nsCycleCollectionParticipant.h"
class nsIExpatSink; class nsIExpatSink;
class nsIExtendedExpatSink; class nsIExtendedExpatSink;
@ -55,9 +56,10 @@ class nsExpatDriver : public nsIDTD,
public nsITokenizer public nsITokenizer
{ {
public: public:
NS_DECL_ISUPPORTS NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSIDTD NS_DECL_NSIDTD
NS_DECL_NSITOKENIZER NS_DECL_NSITOKENIZER
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsExpatDriver, nsIDTD)
nsExpatDriver(); nsExpatDriver();
virtual ~nsExpatDriver(); virtual ~nsExpatDriver();

View File

@ -244,6 +244,17 @@ static PRBool gDumpContent=PR_FALSE;
* default constructor * default constructor
*/ */
nsParser::nsParser() nsParser::nsParser()
{
Initialize(PR_TRUE);
}
nsParser::~nsParser()
{
Cleanup();
}
void
nsParser::Initialize(PRBool aConstructor)
{ {
#ifdef NS_DEBUG #ifdef NS_DEBUG
if (!gDumpContent) { if (!gDumpContent) {
@ -251,13 +262,22 @@ nsParser::nsParser()
} }
#endif #endif
if (aConstructor) {
// Raw pointer
mParserContext = 0;
}
else {
// nsCOMPtrs
mObserver = nsnull;
mParserFilter = nsnull;
}
mContinueEvent = nsnull;
mCharsetSource = kCharsetUninitialized;
mCharset.AssignLiteral("ISO-8859-1"); mCharset.AssignLiteral("ISO-8859-1");
mParserContext=0; mInternalState = NS_OK;
mStreamStatus=0; mStreamStatus = 0;
mCharsetSource=kCharsetUninitialized; mCommand = eViewNormal;
mInternalState=NS_OK;
mContinueEvent=nsnull;
mCommand=eViewNormal;
mFlags = NS_PARSER_FLAG_OBSERVERS_ENABLED | mFlags = NS_PARSER_FLAG_OBSERVERS_ENABLED |
NS_PARSER_FLAG_PARSER_ENABLED | NS_PARSER_FLAG_PARSER_ENABLED |
NS_PARSER_FLAG_CAN_TOKENIZE; NS_PARSER_FLAG_CAN_TOKENIZE;
@ -268,12 +288,9 @@ nsParser::nsParser()
MOZ_TIMER_RESET(mTokenizeTime); MOZ_TIMER_RESET(mTokenizeTime);
} }
/** void
* Destructor nsParser::Cleanup()
*/
nsParser::~nsParser()
{ {
#ifdef NS_DEBUG #ifdef NS_DEBUG
if (gDumpContent) { if (gDumpContent) {
if (mSink) { if (mSink) {
@ -306,14 +323,31 @@ nsParser::~nsParser()
NS_ASSERTION(!(mFlags & NS_PARSER_FLAG_PENDING_CONTINUE_EVENT), "bad"); NS_ASSERTION(!(mFlags & NS_PARSER_FLAG_PENDING_CONTINUE_EVENT), "bad");
} }
NS_IMPL_CYCLE_COLLECTION_2(nsParser, mSink, mObserver) NS_IMPL_CYCLE_COLLECTION_CLASS(nsParser)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsParser)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mSink)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mObserver)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsParser)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mSink)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mObserver)
CParserContext *pc = tmp->mParserContext;
while (pc) {
cb.NoteXPCOMChild(pc->mDTD);
cb.NoteXPCOMChild(pc->mTokenizer);
pc = pc->mPrevContext;
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsParser, nsIParser) NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsParser, nsIParser)
NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsParser, nsIParser) NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsParser, nsIParser)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsParser) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsParser)
NS_INTERFACE_MAP_ENTRY(nsIStreamListener) NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
NS_INTERFACE_MAP_ENTRY(nsIParser) NS_INTERFACE_MAP_ENTRY(nsIParser)
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver) NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIParser) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIParser)
NS_INTERFACE_MAP_END NS_INTERFACE_MAP_END
// The parser continue event is posted only if // The parser continue event is posted only if

View File

@ -381,7 +381,15 @@ class nsParser : public nsIParser,
return sCharsetConverterManager; return sCharsetConverterManager;
} }
protected: virtual void Reset() {
Cleanup();
Initialize();
}
protected:
void Initialize(PRBool aConstructor = PR_FALSE);
void Cleanup();
/** /**
* *