Removed mDoctypeText from nsExpatDriver. This |could| improve Ts/Txul time slightly. b=102345, r=heikki, sr=jst

This commit is contained in:
harishd%netscape.com 2002-01-24 22:15:58 +00:00
Родитель cfb87cef22
Коммит a1ce884f46
11 изменённых файлов: 72 добавлений и 80 удалений

Просмотреть файл

@ -1425,7 +1425,9 @@ nsXMLContentSink::HandleComment(const PRUnichar *aName)
return result; return result;
} }
NS_IMETHODIMP nsXMLContentSink::HandleCDataSection(const PRUnichar *aData, PRUint32 aLength) NS_IMETHODIMP
nsXMLContentSink::HandleCDataSection(const PRUnichar *aData,
PRUint32 aLength)
{ {
FlushText(); FlushText();
@ -1456,7 +1458,8 @@ NS_IMETHODIMP nsXMLContentSink::HandleCDataSection(const PRUnichar *aData, PRUin
} }
NS_IMETHODIMP NS_IMETHODIMP
nsXMLContentSink::HandleDoctypeDecl(const PRUnichar *aDoctype) nsXMLContentSink::HandleDoctypeDecl(const PRUnichar *aDoctype,
PRUint32 aLength)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
@ -1464,12 +1467,8 @@ nsXMLContentSink::HandleDoctypeDecl(const PRUnichar *aDoctype)
if (!doc) if (!doc)
return NS_OK; return NS_OK;
nsAutoString docTypeStr(aDoctype); nsAutoString str(aDoctype, aLength);
nsAutoString str, name, publicId, systemId; nsAutoString name, publicId, systemId;
if (Substring(docTypeStr, 0, 9).Equals(NS_LITERAL_STRING("<!DOCTYPE"))) {
docTypeStr.Right(str, docTypeStr.Length()-9);
}
GetDocTypeToken(str, name, PR_FALSE); GetDocTypeToken(str, name, PR_FALSE);
@ -1484,8 +1483,7 @@ nsXMLContentSink::HandleDoctypeDecl(const PRUnichar *aDoctype)
GetDocTypeToken(str, systemId, PR_TRUE); GetDocTypeToken(str, systemId, PR_TRUE);
} }
// The rest is the internal subset (minus whitespace and the trailing >) // The rest is the internal subset (minus whitespace)
str.Truncate(str.Length()-1); // Delete the trailing >
str.Trim(kWhitespace); str.Trim(kWhitespace);
nsCOMPtr<nsIDOMDocumentType> oldDocType; nsCOMPtr<nsIDOMDocumentType> oldDocType;

Просмотреть файл

@ -1025,7 +1025,7 @@ XULContentSinkImpl::HandleCDataSection(const PRUnichar *aData, PRUint32 aLength)
} }
NS_IMETHODIMP NS_IMETHODIMP
XULContentSinkImpl::HandleDoctypeDecl(const PRUnichar *aDoctype) XULContentSinkImpl::HandleDoctypeDecl(const PRUnichar *aDoctype, PRUint32 aLength)
{ {
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -54,7 +54,8 @@ interface nsIExpatSink : nsISupports
void HandleCDataSection(in wstring aData, void HandleCDataSection(in wstring aData,
in unsigned long aLength); in unsigned long aLength);
void HandleDoctypeDecl(in wstring aDoctype); void HandleDoctypeDecl(in wstring aDoctype,
in unsigned long aLength);
void HandleCharacterData(in wstring aData, void HandleCharacterData(in wstring aData,
in unsigned long aLength); in unsigned long aLength);

Просмотреть файл

@ -51,6 +51,7 @@
#include "prmem.h" #include "prmem.h"
#include "nsTextFormatter.h" #include "nsTextFormatter.h"
static const PRUint32 kNotInDoctype = PRUint32(-1);
static const char* kDTDDirectory = "dtd/"; static const char* kDTDDirectory = "dtd/";
/***************************** EXPAT CALL BACKS *******************************/ /***************************** EXPAT CALL BACKS *******************************/
@ -235,11 +236,12 @@ NS_NewExpatDriver(nsIDTD** aResult) {
nsExpatDriver::nsExpatDriver() nsExpatDriver::nsExpatDriver()
:mExpatParser(0), :mExpatParser(0),
mSink(0), mSink(0),
mInDoctype(0), mBuffer(0),
mInCData(0), mInCData(0),
mBytesParsed(0), mBytesParsed(0),
mBytePosition(0), mBytePosition(0),
mInternalState(NS_OK) mInternalState(NS_OK),
mDoctypePos(-1)
{ {
NS_INIT_REFCNT(); NS_INIT_REFCNT();
} }
@ -305,13 +307,7 @@ nsExpatDriver::HandleComment(const PRUnichar *aValue)
{ {
NS_ASSERTION(mSink, "content sink not found!"); NS_ASSERTION(mSink, "content sink not found!");
if (mInDoctype) { if (mSink && mDoctypePos == kNotInDoctype){
// We do not want comments popping out of the doctype...
mDoctypeText.Append(NS_LITERAL_STRING("<!--"));
mDoctypeText.Append(aValue);
mDoctypeText.Append(NS_LITERAL_STRING("-->"));
}
else if (mSink){
mInternalState = mSink->HandleComment(aValue); mInternalState = mSink->HandleComment(aValue);
} }
@ -341,10 +337,7 @@ nsExpatDriver::HandleDefault(const PRUnichar *aValue,
{ {
NS_ASSERTION(mSink, "content sink not found!"); NS_ASSERTION(mSink, "content sink not found!");
if (mInDoctype) { if (mSink && mDoctypePos == kNotInDoctype) {
mDoctypeText.Append(aValue, aLength);
}
else if (mSink) {
static const PRUnichar newline[] = {'\n','\0'}; static const PRUnichar newline[] = {'\n','\0'};
for (PRUint32 i = 0; i < aLength && NS_SUCCEEDED(mInternalState); i++) { for (PRUint32 i = 0; i < aLength && NS_SUCCEEDED(mInternalState); i++) {
if (aValue[i] == '\n' || aValue[i] == '\r') { if (aValue[i] == '\n' || aValue[i] == '\r') {
@ -380,8 +373,7 @@ nsExpatDriver::HandleEndCdataSection()
nsresult nsresult
nsExpatDriver::HandleStartDoctypeDecl() nsExpatDriver::HandleStartDoctypeDecl()
{ {
mInDoctype = PR_TRUE; mDoctypePos = XML_GetCurrentByteIndex(mExpatParser);
mDoctypeText.Assign(NS_LITERAL_STRING("<!DOCTYPE "));
return NS_OK; return NS_OK;
} }
@ -390,14 +382,15 @@ nsExpatDriver::HandleEndDoctypeDecl()
{ {
NS_ASSERTION(mSink, "content sink not found!"); NS_ASSERTION(mSink, "content sink not found!");
mInDoctype = PR_FALSE; const PRUnichar* doctypeStart = mBuffer + ( mDoctypePos - mBytesParsed ) / 2;
mDoctypeText.Append(PRUnichar('>')); const PRUnichar* doctypeEnd = mBuffer + ( XML_GetCurrentByteIndex(mExpatParser) - mBytesParsed ) / 2;
if(mSink) { if(mSink) {
mInternalState = mSink->HandleDoctypeDecl(mDoctypeText.get()); mInternalState = mSink->HandleDoctypeDecl(doctypeStart, doctypeEnd - doctypeStart);
} }
mDoctypeText.Truncate(); mDoctypePos = kNotInDoctype;
return NS_OK; return NS_OK;
} }
@ -730,9 +723,9 @@ nsExpatDriver::ConsumeToken(nsScanner& aScanner,
while (start != end) { while (start != end) {
PRUint32 fragLength = PRUint32(start.size_forward()); PRUint32 fragLength = PRUint32(start.size_forward());
const PRUnichar* expatBuffer = start.get(); mBuffer = start.get();
mInternalState = ParseBuffer((const char *)expatBuffer, mInternalState = ParseBuffer((const char *)mBuffer,
fragLength * sizeof(PRUnichar), fragLength * sizeof(PRUnichar),
aFlushTokens); aFlushTokens);

Просмотреть файл

@ -82,16 +82,19 @@ protected:
nsresult HandleError(const char *aBuffer, PRUint32 aLength, PRBool aIsFinal); nsresult HandleError(const char *aBuffer, PRUint32 aLength, PRBool aIsFinal);
void GetLine(const char* aSourceBuffer, PRUint32 aLength, PRUint32 aOffset, nsString& aLine); void GetLine(const char* aSourceBuffer, PRUint32 aLength, PRUint32 aOffset, nsString& aLine);
XML_Parser mExpatParser; XML_Parser mExpatParser;
nsIExpatSink* mSink; nsIExpatSink* mSink;
nsString mLastLine; const PRUnichar* mBuffer; // weak
nsString mDoctypeText;
nsString mCDataText; nsString mLastLine;
PRPackedBool mInDoctype; nsString mCDataText;
PRPackedBool mInCData; PRPackedBool mInCData;
PRUint32 mBytesParsed; PRInt32 mBytePosition;
PRInt32 mBytePosition; nsresult mInternalState;
nsresult mInternalState; PRUint32 mBytesParsed;
PRUint32 mDoctypePos;
}; };
nsresult NS_NewExpatDriver(nsIDTD** aDriver); nsresult NS_NewExpatDriver(nsIDTD** aDriver);

Просмотреть файл

@ -1877,7 +1877,7 @@ nsresult nsParser::ResumeParse(PRBool allowIteration, PRBool aIsFinalChunk, PRBo
DidBuildModel(mStreamStatus); DidBuildModel(mStreamStatus);
mInternalState = result; mInternalState = result;
} }
break; return NS_OK;
} }
else if(((NS_OK==result) && (theTokenizerResult==kEOF)) || (result==NS_ERROR_HTMLPARSER_INTERRUPTED)){ else if(((NS_OK==result) && (theTokenizerResult==kEOF)) || (result==NS_ERROR_HTMLPARSER_INTERRUPTED)){

Просмотреть файл

@ -54,7 +54,8 @@ interface nsIExpatSink : nsISupports
void HandleCDataSection(in wstring aData, void HandleCDataSection(in wstring aData,
in unsigned long aLength); in unsigned long aLength);
void HandleDoctypeDecl(in wstring aDoctype); void HandleDoctypeDecl(in wstring aDoctype,
in unsigned long aLength);
void HandleCharacterData(in wstring aData, void HandleCharacterData(in wstring aData,
in unsigned long aLength); in unsigned long aLength);

Просмотреть файл

@ -51,6 +51,7 @@
#include "prmem.h" #include "prmem.h"
#include "nsTextFormatter.h" #include "nsTextFormatter.h"
static const PRUint32 kNotInDoctype = PRUint32(-1);
static const char* kDTDDirectory = "dtd/"; static const char* kDTDDirectory = "dtd/";
/***************************** EXPAT CALL BACKS *******************************/ /***************************** EXPAT CALL BACKS *******************************/
@ -235,11 +236,12 @@ NS_NewExpatDriver(nsIDTD** aResult) {
nsExpatDriver::nsExpatDriver() nsExpatDriver::nsExpatDriver()
:mExpatParser(0), :mExpatParser(0),
mSink(0), mSink(0),
mInDoctype(0), mBuffer(0),
mInCData(0), mInCData(0),
mBytesParsed(0), mBytesParsed(0),
mBytePosition(0), mBytePosition(0),
mInternalState(NS_OK) mInternalState(NS_OK),
mDoctypePos(-1)
{ {
NS_INIT_REFCNT(); NS_INIT_REFCNT();
} }
@ -305,13 +307,7 @@ nsExpatDriver::HandleComment(const PRUnichar *aValue)
{ {
NS_ASSERTION(mSink, "content sink not found!"); NS_ASSERTION(mSink, "content sink not found!");
if (mInDoctype) { if (mSink && mDoctypePos == kNotInDoctype){
// We do not want comments popping out of the doctype...
mDoctypeText.Append(NS_LITERAL_STRING("<!--"));
mDoctypeText.Append(aValue);
mDoctypeText.Append(NS_LITERAL_STRING("-->"));
}
else if (mSink){
mInternalState = mSink->HandleComment(aValue); mInternalState = mSink->HandleComment(aValue);
} }
@ -341,10 +337,7 @@ nsExpatDriver::HandleDefault(const PRUnichar *aValue,
{ {
NS_ASSERTION(mSink, "content sink not found!"); NS_ASSERTION(mSink, "content sink not found!");
if (mInDoctype) { if (mSink && mDoctypePos == kNotInDoctype) {
mDoctypeText.Append(aValue, aLength);
}
else if (mSink) {
static const PRUnichar newline[] = {'\n','\0'}; static const PRUnichar newline[] = {'\n','\0'};
for (PRUint32 i = 0; i < aLength && NS_SUCCEEDED(mInternalState); i++) { for (PRUint32 i = 0; i < aLength && NS_SUCCEEDED(mInternalState); i++) {
if (aValue[i] == '\n' || aValue[i] == '\r') { if (aValue[i] == '\n' || aValue[i] == '\r') {
@ -380,8 +373,7 @@ nsExpatDriver::HandleEndCdataSection()
nsresult nsresult
nsExpatDriver::HandleStartDoctypeDecl() nsExpatDriver::HandleStartDoctypeDecl()
{ {
mInDoctype = PR_TRUE; mDoctypePos = XML_GetCurrentByteIndex(mExpatParser);
mDoctypeText.Assign(NS_LITERAL_STRING("<!DOCTYPE "));
return NS_OK; return NS_OK;
} }
@ -390,14 +382,15 @@ nsExpatDriver::HandleEndDoctypeDecl()
{ {
NS_ASSERTION(mSink, "content sink not found!"); NS_ASSERTION(mSink, "content sink not found!");
mInDoctype = PR_FALSE; const PRUnichar* doctypeStart = mBuffer + ( mDoctypePos - mBytesParsed ) / 2;
mDoctypeText.Append(PRUnichar('>')); const PRUnichar* doctypeEnd = mBuffer + ( XML_GetCurrentByteIndex(mExpatParser) - mBytesParsed ) / 2;
if(mSink) { if(mSink) {
mInternalState = mSink->HandleDoctypeDecl(mDoctypeText.get()); mInternalState = mSink->HandleDoctypeDecl(doctypeStart, doctypeEnd - doctypeStart);
} }
mDoctypeText.Truncate(); mDoctypePos = kNotInDoctype;
return NS_OK; return NS_OK;
} }
@ -730,9 +723,9 @@ nsExpatDriver::ConsumeToken(nsScanner& aScanner,
while (start != end) { while (start != end) {
PRUint32 fragLength = PRUint32(start.size_forward()); PRUint32 fragLength = PRUint32(start.size_forward());
const PRUnichar* expatBuffer = start.get(); mBuffer = start.get();
mInternalState = ParseBuffer((const char *)expatBuffer, mInternalState = ParseBuffer((const char *)mBuffer,
fragLength * sizeof(PRUnichar), fragLength * sizeof(PRUnichar),
aFlushTokens); aFlushTokens);

Просмотреть файл

@ -82,16 +82,19 @@ protected:
nsresult HandleError(const char *aBuffer, PRUint32 aLength, PRBool aIsFinal); nsresult HandleError(const char *aBuffer, PRUint32 aLength, PRBool aIsFinal);
void GetLine(const char* aSourceBuffer, PRUint32 aLength, PRUint32 aOffset, nsString& aLine); void GetLine(const char* aSourceBuffer, PRUint32 aLength, PRUint32 aOffset, nsString& aLine);
XML_Parser mExpatParser; XML_Parser mExpatParser;
nsIExpatSink* mSink; nsIExpatSink* mSink;
nsString mLastLine; const PRUnichar* mBuffer; // weak
nsString mDoctypeText;
nsString mCDataText; nsString mLastLine;
PRPackedBool mInDoctype; nsString mCDataText;
PRPackedBool mInCData; PRPackedBool mInCData;
PRUint32 mBytesParsed; PRInt32 mBytePosition;
PRInt32 mBytePosition; nsresult mInternalState;
nsresult mInternalState; PRUint32 mBytesParsed;
PRUint32 mDoctypePos;
}; };
nsresult NS_NewExpatDriver(nsIDTD** aDriver); nsresult NS_NewExpatDriver(nsIDTD** aDriver);

Просмотреть файл

@ -1877,7 +1877,7 @@ nsresult nsParser::ResumeParse(PRBool allowIteration, PRBool aIsFinalChunk, PRBo
DidBuildModel(mStreamStatus); DidBuildModel(mStreamStatus);
mInternalState = result; mInternalState = result;
} }
break; return NS_OK;
} }
else if(((NS_OK==result) && (theTokenizerResult==kEOF)) || (result==NS_ERROR_HTMLPARSER_INTERRUPTED)){ else if(((NS_OK==result) && (theTokenizerResult==kEOF)) || (result==NS_ERROR_HTMLPARSER_INTERRUPTED)){

Просмотреть файл

@ -603,7 +603,7 @@ RDFContentSinkImpl::HandleCDataSection(const PRUnichar *aData,
} }
NS_IMETHODIMP NS_IMETHODIMP
RDFContentSinkImpl::HandleDoctypeDecl(const PRUnichar *aDoctype) RDFContentSinkImpl::HandleDoctypeDecl(const PRUnichar *aDoctype, PRUint32 aLength)
{ {
return NS_OK; return NS_OK;
} }