From f2f5d2830878bda7fdda8018ec2285f1225cc7bd Mon Sep 17 00:00:00 2001 From: rickg Date: Thu, 21 May 1998 20:38:32 +0000 Subject: [PATCH] incremental parsing; xml support; token handler dispatching; performance git-svn-id: svn://10.0.0.236/trunk@2126 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/htmlparser/src/CNavDelegate.cpp | 27 +- mozilla/htmlparser/src/CNavDelegate.h | 2 +- mozilla/htmlparser/src/COtherDelegate.cpp | 4 +- mozilla/htmlparser/src/COtherDelegate.h | 2 +- mozilla/htmlparser/src/nsHTMLContentSink.cpp | 61 +- mozilla/htmlparser/src/nsHTMLContentSink.h | 28 +- mozilla/htmlparser/src/nsHTMLParser.cpp | 679 +++++++++--------- mozilla/htmlparser/src/nsHTMLParser.h | 118 ++- mozilla/htmlparser/src/nsHTMLTokens.cpp | 215 +++--- mozilla/htmlparser/src/nsHTMLTokens.h | 12 +- mozilla/htmlparser/src/nsIContentSink.h | 8 +- mozilla/htmlparser/src/nsIHTMLContentSink.h | 28 +- mozilla/htmlparser/src/nsIParser.h | 4 +- mozilla/htmlparser/src/nsParserTypes.h | 2 + mozilla/htmlparser/src/nsScanner.cpp | 25 + mozilla/htmlparser/src/nsScanner.h | 12 +- mozilla/htmlparser/src/nsToken.cpp | 29 +- mozilla/htmlparser/src/nsToken.h | 21 +- mozilla/htmlparser/src/nsTokenHandler.cpp | 566 +-------------- mozilla/htmlparser/src/nsTokenHandler.h | 118 +-- mozilla/htmlparser/src/nsTokenizer.cpp | 14 + mozilla/htmlparser/src/nsTokenizer.h | 7 + .../parser/htmlparser/src/CNavDelegate.cpp | 27 +- mozilla/parser/htmlparser/src/CNavDelegate.h | 2 +- .../parser/htmlparser/src/COtherDelegate.cpp | 4 +- .../parser/htmlparser/src/COtherDelegate.h | 2 +- .../htmlparser/src/nsHTMLContentSink.cpp | 61 +- .../parser/htmlparser/src/nsHTMLContentSink.h | 28 +- .../parser/htmlparser/src/nsHTMLParser.cpp | 679 +++++++++--------- mozilla/parser/htmlparser/src/nsHTMLParser.h | 118 ++- .../parser/htmlparser/src/nsHTMLTokens.cpp | 215 +++--- mozilla/parser/htmlparser/src/nsHTMLTokens.h | 12 +- .../parser/htmlparser/src/nsIContentSink.h | 8 +- .../htmlparser/src/nsIHTMLContentSink.h | 28 +- mozilla/parser/htmlparser/src/nsIParser.h | 4 +- mozilla/parser/htmlparser/src/nsParserTypes.h | 2 + mozilla/parser/htmlparser/src/nsScanner.cpp | 25 + mozilla/parser/htmlparser/src/nsScanner.h | 12 +- mozilla/parser/htmlparser/src/nsToken.cpp | 29 +- mozilla/parser/htmlparser/src/nsToken.h | 21 +- .../parser/htmlparser/src/nsTokenHandler.cpp | 566 +-------------- .../parser/htmlparser/src/nsTokenHandler.h | 118 +-- mozilla/parser/htmlparser/src/nsTokenizer.cpp | 14 + mozilla/parser/htmlparser/src/nsTokenizer.h | 7 + 44 files changed, 1476 insertions(+), 2488 deletions(-) diff --git a/mozilla/htmlparser/src/CNavDelegate.cpp b/mozilla/htmlparser/src/CNavDelegate.cpp index 857a233b1c6..14c5cf34e03 100644 --- a/mozilla/htmlparser/src/CNavDelegate.cpp +++ b/mozilla/htmlparser/src/CNavDelegate.cpp @@ -136,18 +136,21 @@ PRInt32 CNavDelegate::ConsumeTag(PRUnichar aChar,CScanner& aScanner,CToken*& aTo * @param aScanner: see nsScanner.h * @return */ -PRInt32 CNavDelegate::ConsumeAttributes(PRUnichar aChar,CScanner& aScanner) { +PRInt32 CNavDelegate::ConsumeAttributes(PRUnichar aChar,CScanner& aScanner,CToken*& aToken) { PRBool done=PR_FALSE; PRInt32 result=kNoError; nsAutoString as(""); + PRInt16 theAttrCount=0; while((!done) && (result==kNoError)) { CToken* theToken= new CAttributeToken(as); if(theToken){ result=theToken->Consume(aChar,aScanner); //tell new token to finish consuming text... if(kNoError==result){ + theAttrCount++; mTokenDeque.Push(theToken); }//if + else delete theToken; //we can't keep it... }//if if(kNoError==result){ @@ -158,6 +161,24 @@ PRInt32 CNavDelegate::ConsumeAttributes(PRUnichar aChar,CScanner& aScanner) { }//if }//if }//while + + //ok, this is a bit complicated, so follow closely. + //Since we're incremental (but pessimistic), it is possible that even though + //we've eaten a few delicious attributes, we can't keep them because + //we couldn't eat all of them (up to an including the close > for this tag). + //Therefore, we need to remove the ones we just created from the tokendeque, + //and destroy them. (They'll get reconsumed on the next incremental pass). + //NOTE: This process can be enhanced later on by adding state to the delegate + // telling us that we're in the attribute consumption phase. + // Remember the mantra: Crawl, Walk, Run! + if(kNoError==result) { + aToken->SetAttributeCount(theAttrCount); + } + else { + while(theAttrCount--) { + delete mTokenDeque.PopBack(); + } + } return result; } @@ -200,7 +221,7 @@ PRInt32 CNavDelegate::ConsumeStartTag(PRUnichar aChar,CScanner& aScanner,CToken* result= aToken->Consume(aChar,aScanner); //tell new token to finish consuming text... if(kNoError==result) { if(((CStartToken*)aToken)->IsAttributed()) { - result=ConsumeAttributes(aChar,aScanner); + result=ConsumeAttributes(aChar,aScanner,aToken); } //now that that's over with, we have one more problem to solve. //In the case that we just read a