From 5ac270730dbe6f53b8eaa1ff1655d35e1f960c1f Mon Sep 17 00:00:00 2001 From: Blake Kaplan Date: Thu, 30 Oct 2008 14:31:00 -0700 Subject: [PATCH] Bug 461031 - Bring a little more sanity to parser notifications of the content sink. This should help increase responsiveness, especially on pages with lots of inline scripts. r+sr=jst --- .../src/nsPlacesImportExportService.cpp | 3 +-- content/base/src/mozSanitizingSerializer.h | 3 +-- content/base/src/nsContentSink.cpp | 2 +- content/base/src/nsContentSink.h | 2 +- content/base/src/nsPlainTextSerializer.h | 2 +- .../html/document/src/nsHTMLContentSink.cpp | 23 +++++++------------ .../src/nsHTMLFragmentContentSink.cpp | 3 +-- content/xml/document/src/nsXMLContentSink.cpp | 4 ++-- content/xml/document/src/nsXMLContentSink.h | 2 +- .../src/xslt/txMozillaStylesheetCompiler.cpp | 2 +- content/xul/document/src/nsXULContentSink.h | 2 +- parser/htmlparser/public/nsIContentSink.h | 21 ++++++++--------- parser/htmlparser/public/nsIHTMLContentSink.h | 11 +++------ parser/htmlparser/src/CNavDTD.cpp | 2 -- parser/htmlparser/src/nsLoggingSink.cpp | 2 +- parser/htmlparser/src/nsLoggingSink.h | 3 +-- parser/htmlparser/src/nsParser.cpp | 10 +++++++- parser/htmlparser/src/nsViewSourceHTML.cpp | 2 -- parser/xml/src/nsSAXXMLReader.h | 2 +- rdf/base/src/nsRDFContentSink.cpp | 4 ++-- 20 files changed, 45 insertions(+), 60 deletions(-) diff --git a/browser/components/places/src/nsPlacesImportExportService.cpp b/browser/components/places/src/nsPlacesImportExportService.cpp index 38da788dbb2..5856e4d1112 100644 --- a/browser/components/places/src/nsPlacesImportExportService.cpp +++ b/browser/components/places/src/nsPlacesImportExportService.cpp @@ -344,7 +344,7 @@ public: NS_DECL_ISUPPORTS // nsIContentSink (superclass of nsIHTMLContentSink) - NS_IMETHOD WillTokenize() { return NS_OK; } + NS_IMETHOD WillParse() { return NS_OK; } NS_IMETHOD WillBuildModel() { return NS_OK; } NS_IMETHOD DidBuildModel() { return NS_OK; } NS_IMETHOD WillInterrupt() { return NS_OK; } @@ -360,7 +360,6 @@ public: NS_IMETHOD EndContext(PRInt32 aPosition) { return NS_OK; } NS_IMETHOD IsEnabled(PRInt32 aTag, PRBool* aReturn) { *aReturn = PR_TRUE; return NS_OK; } - NS_IMETHOD WillProcessTokens() { return NS_OK; } NS_IMETHOD DidProcessTokens() { return NS_OK; } NS_IMETHOD WillProcessAToken() { return NS_OK; } NS_IMETHOD DidProcessAToken() { return NS_OK; } diff --git a/content/base/src/mozSanitizingSerializer.h b/content/base/src/mozSanitizingSerializer.h index a24f9a733dd..60fdd006e35 100644 --- a/content/base/src/mozSanitizingSerializer.h +++ b/content/base/src/mozSanitizingSerializer.h @@ -99,7 +99,7 @@ public: nsAString& aStr); // nsIContentSink - NS_IMETHOD WillTokenize(void) { return NS_OK; } + NS_IMETHOD WillParse(void) { return NS_OK; } NS_IMETHOD WillBuildModel(void) { return NS_OK; } NS_IMETHOD DidBuildModel(void) { return NS_OK; } NS_IMETHOD WillInterrupt(void) { return NS_OK; } @@ -123,7 +123,6 @@ public: NS_IMETHOD_(PRBool) IsFormOnStack() { return PR_FALSE; } NS_IMETHOD BeginContext(PRInt32 aPosition) { return NS_OK; } NS_IMETHOD EndContext(PRInt32 aPosition) { return NS_OK; } - NS_IMETHOD WillProcessTokens(void) { return NS_OK; } NS_IMETHOD DidProcessTokens(void) { return NS_OK; } NS_IMETHOD WillProcessAToken(void) { return NS_OK; } NS_IMETHOD DidProcessAToken(void) { return NS_OK; } diff --git a/content/base/src/nsContentSink.cpp b/content/base/src/nsContentSink.cpp index 442b52dac80..17ebda8cd17 100644 --- a/content/base/src/nsContentSink.cpp +++ b/content/base/src/nsContentSink.cpp @@ -1714,7 +1714,7 @@ nsContentSink::DropParserAndPerfHint(void) } nsresult -nsContentSink::WillProcessTokensImpl(void) +nsContentSink::WillParseImpl(void) { if (mCanInterruptParser) { mDelayTimerStart = PR_IntervalToMicroseconds(PR_IntervalNow()); diff --git a/content/base/src/nsContentSink.h b/content/base/src/nsContentSink.h index 3a61d3236ea..f2c8c38bdbb 100644 --- a/content/base/src/nsContentSink.h +++ b/content/base/src/nsContentSink.h @@ -131,13 +131,13 @@ class nsContentSink : public nsICSSLoaderObserver, virtual nsresult ProcessMETATag(nsIContent* aContent); // nsIContentSink implementation helpers + NS_HIDDEN_(nsresult) WillParseImpl(void); NS_HIDDEN_(nsresult) WillInterruptImpl(void); NS_HIDDEN_(nsresult) WillResumeImpl(void); NS_HIDDEN_(nsresult) DidProcessATokenImpl(void); NS_HIDDEN_(void) WillBuildModelImpl(void); NS_HIDDEN_(void) DidBuildModelImpl(void); NS_HIDDEN_(void) DropParserAndPerfHint(void); - NS_HIDDEN_(nsresult) WillProcessTokensImpl(void); void NotifyAppend(nsIContent* aContent, PRUint32 aStartIndex); diff --git a/content/base/src/nsPlainTextSerializer.h b/content/base/src/nsPlainTextSerializer.h index 43b87543304..d484cf60362 100644 --- a/content/base/src/nsPlainTextSerializer.h +++ b/content/base/src/nsPlainTextSerializer.h @@ -96,7 +96,7 @@ public: nsAString& aStr); // nsIContentSink - NS_IMETHOD WillTokenize(void) { return NS_OK; } + NS_IMETHOD WillParse(void) { return NS_OK; } NS_IMETHOD WillBuildModel(void) { return NS_OK; } NS_IMETHOD DidBuildModel(void) { return NS_OK; } NS_IMETHOD WillInterrupt(void) { return NS_OK; } diff --git a/content/html/document/src/nsHTMLContentSink.cpp b/content/html/document/src/nsHTMLContentSink.cpp index 4809840cd19..9c9be73c2a5 100644 --- a/content/html/document/src/nsHTMLContentSink.cpp +++ b/content/html/document/src/nsHTMLContentSink.cpp @@ -181,7 +181,7 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIContentSink - NS_IMETHOD WillTokenize(void); + NS_IMETHOD WillParse(void); NS_IMETHOD WillBuildModel(void); NS_IMETHOD DidBuildModel(void); NS_IMETHOD WillInterrupt(void); @@ -199,7 +199,6 @@ public: NS_IMETHOD AddComment(const nsIParserNode& aNode); NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode); NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode); - NS_IMETHOD WillProcessTokens(void); NS_IMETHOD DidProcessTokens(void); NS_IMETHOD WillProcessAToken(void); NS_IMETHOD DidProcessAToken(void); @@ -1744,6 +1743,12 @@ HTMLContentSink::Init(nsIDocument* aDoc, return NS_OK; } +NS_IMETHODIMP +HTMLContentSink::WillParse(void) +{ + return WillParseImpl(); +} + NS_IMETHODIMP HTMLContentSink::WillBuildModel(void) { @@ -2696,18 +2701,6 @@ HTMLContentSink::AddDocTypeDecl(const nsIParserNode& aNode) return rv; } -NS_IMETHODIMP -HTMLContentSink::WillTokenize(void) -{ - return NS_OK; -} - -NS_IMETHODIMP -HTMLContentSink::WillProcessTokens(void) -{ - return WillProcessTokensImpl(); -} - NS_IMETHODIMP HTMLContentSink::DidProcessTokens(void) { @@ -2729,7 +2722,7 @@ HTMLContentSink::DidProcessAToken(void) NS_IMETHODIMP HTMLContentSink::WillInterrupt() { - return WillInterruptImpl(); + return WillInterruptImpl(); } NS_IMETHODIMP diff --git a/content/html/document/src/nsHTMLFragmentContentSink.cpp b/content/html/document/src/nsHTMLFragmentContentSink.cpp index 5a04d39f2b6..9380a12fbe5 100644 --- a/content/html/document/src/nsHTMLFragmentContentSink.cpp +++ b/content/html/document/src/nsHTMLFragmentContentSink.cpp @@ -87,7 +87,7 @@ public: NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW // nsIContentSink - NS_IMETHOD WillTokenize(void) { return NS_OK; } + NS_IMETHOD WillParse(void) { return NS_OK; } NS_IMETHOD WillBuildModel(void); NS_IMETHOD DidBuildModel(void); NS_IMETHOD WillInterrupt(void); @@ -106,7 +106,6 @@ public: return NS_OK; } NS_IMETHOD_(PRBool) IsFormOnStack() { return PR_FALSE; } - NS_IMETHOD WillProcessTokens(void) { return NS_OK; } NS_IMETHOD DidProcessTokens(void) { return NS_OK; } NS_IMETHOD WillProcessAToken(void) { return NS_OK; } NS_IMETHOD DidProcessAToken(void) { return NS_OK; } diff --git a/content/xml/document/src/nsXMLContentSink.cpp b/content/xml/document/src/nsXMLContentSink.cpp index afe3cba5658..7c5c5000fa1 100644 --- a/content/xml/document/src/nsXMLContentSink.cpp +++ b/content/xml/document/src/nsXMLContentSink.cpp @@ -205,9 +205,9 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END // nsIContentSink NS_IMETHODIMP -nsXMLContentSink::WillTokenize(void) +nsXMLContentSink::WillParse(void) { - return WillProcessTokensImpl(); + return WillParseImpl(); } NS_IMETHODIMP diff --git a/content/xml/document/src/nsXMLContentSink.h b/content/xml/document/src/nsXMLContentSink.h index 4d652a7c7a9..0231d9f52f7 100644 --- a/content/xml/document/src/nsXMLContentSink.h +++ b/content/xml/document/src/nsXMLContentSink.h @@ -90,7 +90,7 @@ public: NS_DECL_NSIEXPATSINK // nsIContentSink - NS_IMETHOD WillTokenize(void); + NS_IMETHOD WillParse(void); NS_IMETHOD WillBuildModel(void); NS_IMETHOD DidBuildModel(void); NS_IMETHOD WillInterrupt(void); diff --git a/content/xslt/src/xslt/txMozillaStylesheetCompiler.cpp b/content/xslt/src/xslt/txMozillaStylesheetCompiler.cpp index dcc4d29cd44..f2d40f57c26 100644 --- a/content/xslt/src/xslt/txMozillaStylesheetCompiler.cpp +++ b/content/xslt/src/xslt/txMozillaStylesheetCompiler.cpp @@ -108,7 +108,7 @@ public: NS_DECL_NSIINTERFACEREQUESTOR // nsIContentSink - NS_IMETHOD WillTokenize(void) { return NS_OK; } + NS_IMETHOD WillParse(void) { return NS_OK; } NS_IMETHOD WillBuildModel(void) { return NS_OK; } NS_IMETHOD DidBuildModel(); NS_IMETHOD WillInterrupt(void) { return NS_OK; } diff --git a/content/xul/document/src/nsXULContentSink.h b/content/xul/document/src/nsXULContentSink.h index 0f324db431a..1285d1a5157 100644 --- a/content/xul/document/src/nsXULContentSink.h +++ b/content/xul/document/src/nsXULContentSink.h @@ -69,7 +69,7 @@ public: NS_DECL_NSIEXPATSINK // nsIContentSink - NS_IMETHOD WillTokenize(void) { return NS_OK; } + NS_IMETHOD WillParse(void) { return NS_OK; } NS_IMETHOD WillBuildModel(void); NS_IMETHOD DidBuildModel(void); NS_IMETHOD WillInterrupt(void); diff --git a/parser/htmlparser/public/nsIContentSink.h b/parser/htmlparser/public/nsIContentSink.h index dfe31aa567c..55bed1f5c7a 100644 --- a/parser/htmlparser/public/nsIContentSink.h +++ b/parser/htmlparser/public/nsIContentSink.h @@ -65,22 +65,19 @@ public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICONTENT_SINK_IID) /** - * This method gets called before the nsParser calls tokenize. - * This is needed because the XML side actually builds - * the content model as part of the tokenization and - * not on BuildModel(). The XML side can use this call - * to do stuff that the HTML side does in WillProcessTokens(). - * - * @update 2006-10-17 hsivonen + * This method is called by the parser when it is entered from + * the event loop. The content sink wants to know how long the + * parser has been active since we last processed events on the + * main event loop and this call calibrates that measurement. */ - NS_IMETHOD WillTokenize(void)=0; + NS_IMETHOD WillParse(void)=0; /** * This method gets called when the parser begins the process * of building the content model via the content sink. * * @update 5/7/98 gess - */ + */ NS_IMETHOD WillBuildModel(void)=0; /** @@ -88,7 +85,7 @@ public: * of building the content model via the content sink. * * @update 5/7/98 gess - */ + */ NS_IMETHOD DidBuildModel()=0; /** @@ -97,7 +94,7 @@ public: * more data is available. * * @update 5/7/98 gess - */ + */ NS_IMETHOD WillInterrupt(void)=0; /** @@ -105,7 +102,7 @@ public: * and we're about to start dumping content again to the sink. * * @update 5/7/98 gess - */ + */ NS_IMETHOD WillResume(void)=0; /** diff --git a/parser/htmlparser/public/nsIHTMLContentSink.h b/parser/htmlparser/public/nsIHTMLContentSink.h index 2834f54bb9c..73e6b508676 100644 --- a/parser/htmlparser/public/nsIHTMLContentSink.h +++ b/parser/htmlparser/public/nsIHTMLContentSink.h @@ -82,9 +82,10 @@ #include "nsIContentSink.h" #include "nsHTMLTags.h" +// d19e6730-5e2f-4131-89db-8a918515097d #define NS_IHTML_CONTENT_SINK_IID \ -{ 0x73b5a072, 0x0f87, 0x4d07, \ - { 0xa8, 0x16, 0xe6, 0xac, 0x73, 0xa7, 0x04, 0x3c } } +{ 0xd19e6730, 0x5e2f, 0x4131, \ + { 0x89, 0xdb, 0x8a, 0x91, 0x85, 0x15, 0x09, 0x7d } } #if defined(XP_MAC) @@ -130,12 +131,6 @@ public: */ NS_IMETHOD IsEnabled(PRInt32 aTag, PRBool* aReturn) = 0; - /** - * This method is called when parser is about to begin - * synchronously processing a chunk of tokens. - */ - NS_IMETHOD WillProcessTokens(void) = 0; - /** * This method is called when parser has * completed processing a chunk of tokens. The processing of the diff --git a/parser/htmlparser/src/CNavDTD.cpp b/parser/htmlparser/src/CNavDTD.cpp index 3ad465b446a..623f8f84e14 100644 --- a/parser/htmlparser/src/CNavDTD.cpp +++ b/parser/htmlparser/src/CNavDTD.cpp @@ -323,8 +323,6 @@ CNavDTD::BuildModel(nsIParser* aParser, } } - mSink->WillProcessTokens(); - while (NS_SUCCEEDED(result)) { if (!(mFlags & NS_DTD_FLAG_STOP_PARSING)) { CToken* theToken = mTokenizer->PopToken(); diff --git a/parser/htmlparser/src/nsLoggingSink.cpp b/parser/htmlparser/src/nsLoggingSink.cpp index 8d43187c24c..af505341b61 100644 --- a/parser/htmlparser/src/nsLoggingSink.cpp +++ b/parser/htmlparser/src/nsLoggingSink.cpp @@ -94,7 +94,7 @@ void WriteTabs(PRFileDesc * out,int aTabCount) { } NS_IMETHODIMP -nsLoggingSink::WillTokenize() { +nsLoggingSink::WillParse() { return NS_OK; } diff --git a/parser/htmlparser/src/nsLoggingSink.h b/parser/htmlparser/src/nsLoggingSink.h index ffffa7d6812..1e7c7dd7c24 100644 --- a/parser/htmlparser/src/nsLoggingSink.h +++ b/parser/htmlparser/src/nsLoggingSink.h @@ -60,7 +60,7 @@ public: NS_DECL_ISUPPORTS // nsIContentSink - NS_IMETHOD WillTokenize(); + NS_IMETHOD WillParse(); NS_IMETHOD WillBuildModel(); NS_IMETHOD DidBuildModel(); NS_IMETHOD WillInterrupt(); @@ -86,7 +86,6 @@ public: NS_IMETHOD BeginContext(PRInt32 aPosition); NS_IMETHOD EndContext(PRInt32 aPosition); - NS_IMETHOD WillProcessTokens(void) { return NS_OK; } NS_IMETHOD DidProcessTokens(void) { return NS_OK; } NS_IMETHOD WillProcessAToken(void) { return NS_OK; } NS_IMETHOD DidProcessAToken(void) { return NS_OK; } diff --git a/parser/htmlparser/src/nsParser.cpp b/parser/htmlparser/src/nsParser.cpp index 85ebb465587..81d1bd028f8 100644 --- a/parser/htmlparser/src/nsParser.cpp +++ b/parser/htmlparser/src/nsParser.cpp @@ -1724,6 +1724,9 @@ nsParser::ContinueInterruptedParsing() PRBool isFinalChunk = mParserContext && mParserContext->mStreamListenerState == eOnStop; + if (mSink) { + mSink->WillParse(); + } result = ResumeParse(PR_TRUE, isFinalChunk); // Ref. bug 57999 if (result != NS_OK) { @@ -2867,6 +2870,9 @@ nsParser::OnDataAvailable(nsIRequest *request, nsISupports* aContext, // Don't bother to start parsing until we've seen some // non-whitespace data if (theContext->mScanner->FirstNonWhitespacePosition() >= 0) { + if (mSink) { + mSink->WillParse(); + } rv = ResumeParse(); } } else { @@ -2915,6 +2921,9 @@ nsParser::OnStopRequest(nsIRequest *request, nsISupports* aContext, mParserFilter->Finish(); if (NS_SUCCEEDED(rv)) { + if (mSink) { + mSink->WillParse(); + } rv = ResumeParse(PR_TRUE, PR_TRUE); } @@ -2964,7 +2973,6 @@ nsParser::WillTokenize(PRBool aIsFinalChunk) NS_IPARSER_FLAG_HTML; nsresult result = mParserContext->GetTokenizer(type, mSink, theTokenizer); NS_ENSURE_SUCCESS(result, PR_FALSE); - mSink->WillTokenize(); return NS_SUCCEEDED(theTokenizer->WillTokenize(aIsFinalChunk, &mTokenAllocator)); } diff --git a/parser/htmlparser/src/nsViewSourceHTML.cpp b/parser/htmlparser/src/nsViewSourceHTML.cpp index f81bad9b7fc..5359ff59d96 100644 --- a/parser/htmlparser/src/nsViewSourceHTML.cpp +++ b/parser/htmlparser/src/nsViewSourceHTML.cpp @@ -451,8 +451,6 @@ NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,nsITokenizer* aToke } } - mSink->WillProcessTokens(); - while(NS_SUCCEEDED(result)){ CToken* theToken=mTokenizer->PopToken(); if(theToken) { diff --git a/parser/xml/src/nsSAXXMLReader.h b/parser/xml/src/nsSAXXMLReader.h index c42edc80a2c..1d81a24decd 100644 --- a/parser/xml/src/nsSAXXMLReader.h +++ b/parser/xml/src/nsSAXXMLReader.h @@ -72,7 +72,7 @@ public: nsSAXXMLReader(); //nsIContentSink - NS_IMETHOD WillTokenize() + NS_IMETHOD WillParse() { return NS_OK; } diff --git a/rdf/base/src/nsRDFContentSink.cpp b/rdf/base/src/nsRDFContentSink.cpp index a741456d293..dff900420c6 100644 --- a/rdf/base/src/nsRDFContentSink.cpp +++ b/rdf/base/src/nsRDFContentSink.cpp @@ -159,7 +159,7 @@ public: NS_DECL_NSIEXPATSINK // nsIContentSink - NS_IMETHOD WillTokenize(void); + NS_IMETHOD WillParse(void); NS_IMETHOD WillBuildModel(void); NS_IMETHOD DidBuildModel(void); NS_IMETHOD WillInterrupt(void); @@ -607,7 +607,7 @@ RDFContentSinkImpl::ReportError(const PRUnichar* aErrorText, // nsIContentSink interface NS_IMETHODIMP -RDFContentSinkImpl::WillTokenize(void) +RDFContentSinkImpl::WillParse(void) { return NS_OK; }