From 5012f4e582270745ef4461db19bb0e14bb5e0159 Mon Sep 17 00:00:00 2001 From: "rickg%netscape.com" Date: Fri, 26 Feb 1999 06:33:54 +0000 Subject: [PATCH] small bug fixes and removal of global statics git-svn-id: svn://10.0.0.236/trunk@22072 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/base/src/nsDeque.cpp | 12 +++- mozilla/base/src/nsDeque.h | 4 +- .../editor/txmgr/src/nsTransactionStack.cpp | 2 +- mozilla/editor/txmgr/src/nsTransactionStack.h | 1 - mozilla/htmlparser/src/CNavDTD.cpp | 60 +++++++------------ mozilla/htmlparser/src/COtherDTD.cpp | 7 --- mozilla/htmlparser/src/CParserContext.cpp | 13 ---- mozilla/htmlparser/src/CParserContext.h | 2 - mozilla/htmlparser/src/CRtfDTD.cpp | 6 +- mozilla/htmlparser/src/nsDTDUtils.cpp | 40 ++++++++++++- mozilla/htmlparser/src/nsDTDUtils.h | 1 + mozilla/htmlparser/src/nsElementTable.cpp | 9 +-- mozilla/htmlparser/src/nsExpatDTD.cpp | 4 -- mozilla/htmlparser/src/nsExpatTokenizer.cpp | 1 - mozilla/htmlparser/src/nsHTMLTokenizer.cpp | 27 ++++----- mozilla/htmlparser/src/nsHTMLTokens.cpp | 24 ++++---- mozilla/htmlparser/src/nsIParser.h | 1 + mozilla/htmlparser/src/nsParser.cpp | 33 ++++------ mozilla/htmlparser/src/nsParserNode.cpp | 13 ++-- mozilla/htmlparser/src/nsParserNode.h | 2 +- mozilla/htmlparser/src/nsValidDTD.cpp | 9 --- mozilla/htmlparser/src/nsViewSourceHTML.cpp | 14 +---- mozilla/htmlparser/src/nsViewSourceHTML.h | 3 - mozilla/htmlparser/src/nsWellFormedDTD.cpp | 15 +---- mozilla/htmlparser/src/nsWellFormedDTD.h | 3 - mozilla/htmlparser/src/nsXIFDTD.cpp | 5 +- mozilla/htmlparser/src/nsXIFDTD.h | 2 - mozilla/htmlparser/src/nsXMLTokenizer.cpp | 7 ++- mozilla/layout/base/nsCSSFrameConstructor.cpp | 6 +- .../html/style/src/nsCSSFrameConstructor.cpp | 6 +- mozilla/parser/htmlparser/src/CNavDTD.cpp | 60 +++++++------------ mozilla/parser/htmlparser/src/COtherDTD.cpp | 7 --- .../parser/htmlparser/src/CParserContext.cpp | 13 ---- .../parser/htmlparser/src/CParserContext.h | 2 - mozilla/parser/htmlparser/src/CRtfDTD.cpp | 6 +- mozilla/parser/htmlparser/src/nsDTDUtils.cpp | 40 ++++++++++++- mozilla/parser/htmlparser/src/nsDTDUtils.h | 1 + .../parser/htmlparser/src/nsElementTable.cpp | 9 +-- mozilla/parser/htmlparser/src/nsExpatDTD.cpp | 4 -- .../htmlparser/src/nsExpatTokenizer.cpp | 1 - .../parser/htmlparser/src/nsHTMLTokenizer.cpp | 27 ++++----- .../parser/htmlparser/src/nsHTMLTokens.cpp | 24 ++++---- mozilla/parser/htmlparser/src/nsIParser.h | 1 + mozilla/parser/htmlparser/src/nsParser.cpp | 33 ++++------ .../parser/htmlparser/src/nsParserNode.cpp | 13 ++-- mozilla/parser/htmlparser/src/nsParserNode.h | 2 +- mozilla/parser/htmlparser/src/nsValidDTD.cpp | 9 --- .../htmlparser/src/nsViewSourceHTML.cpp | 14 +---- .../parser/htmlparser/src/nsViewSourceHTML.h | 3 - .../parser/htmlparser/src/nsWellFormedDTD.cpp | 15 +---- .../parser/htmlparser/src/nsWellFormedDTD.h | 3 - mozilla/parser/htmlparser/src/nsXIFDTD.cpp | 5 +- mozilla/parser/htmlparser/src/nsXIFDTD.h | 2 - .../parser/htmlparser/src/nsXMLTokenizer.cpp | 7 ++- mozilla/xpcom/ds/nsDeque.cpp | 12 +++- mozilla/xpcom/ds/nsDeque.h | 4 +- 56 files changed, 279 insertions(+), 370 deletions(-) diff --git a/mozilla/base/src/nsDeque.cpp b/mozilla/base/src/nsDeque.cpp index ac5ead5752d..94443a2c5cd 100644 --- a/mozilla/base/src/nsDeque.cpp +++ b/mozilla/base/src/nsDeque.cpp @@ -28,8 +28,8 @@ * @update gess4/18/98 * @return new deque */ -nsDeque::nsDeque(nsDequeFunctor& aMemDestroyer) : mMemDestroyer(aMemDestroyer) { - mMemDestroyer=aMemDestroyer; +nsDeque::nsDeque(nsDequeFunctor* aDeallocator) { + mDeallocator=aDeallocator; mCapacity=eGrowthDelta; mOrigin=mSize=0; mData=new void*[mCapacity]; @@ -44,6 +44,10 @@ nsDeque::~nsDeque() { Erase(); delete [] mData; mData=0; + if(mDeallocator) { + delete mDeallocator; + } + mDeallocator=0; } @@ -82,7 +86,9 @@ nsDeque& nsDeque::Empty() { * @return this */ nsDeque& nsDeque::Erase() { - ForEach(mMemDestroyer); + if(mDeallocator) { + ForEach(*mDeallocator); + } return Empty(); } diff --git a/mozilla/base/src/nsDeque.h b/mozilla/base/src/nsDeque.h index 01add17a223..7c8314786dd 100644 --- a/mozilla/base/src/nsDeque.h +++ b/mozilla/base/src/nsDeque.h @@ -71,7 +71,7 @@ public: class NS_BASE nsDeque { friend class nsDequeIterator; public: - nsDeque(nsDequeFunctor& aMemDestroyer); + nsDeque(nsDequeFunctor* aDeallocator); ~nsDeque(); /** @@ -215,7 +215,7 @@ protected: PRInt32 mSize; PRInt32 mCapacity; PRInt32 mOrigin; - nsDequeFunctor& mMemDestroyer; + nsDequeFunctor* mDeallocator; void** mData; diff --git a/mozilla/editor/txmgr/src/nsTransactionStack.cpp b/mozilla/editor/txmgr/src/nsTransactionStack.cpp index 06daf9edd4d..aab78db9756 100644 --- a/mozilla/editor/txmgr/src/nsTransactionStack.cpp +++ b/mozilla/editor/txmgr/src/nsTransactionStack.cpp @@ -20,7 +20,7 @@ #include "nsCOMPtr.h" nsTransactionStack::nsTransactionStack() - : mRF(), mQue(mRF) + : mQue(new nsTransactionReleaseFunctor()) { } diff --git a/mozilla/editor/txmgr/src/nsTransactionStack.h b/mozilla/editor/txmgr/src/nsTransactionStack.h index d9334ea0699..2134e42c5a3 100644 --- a/mozilla/editor/txmgr/src/nsTransactionStack.h +++ b/mozilla/editor/txmgr/src/nsTransactionStack.h @@ -35,7 +35,6 @@ public: class nsTransactionStack { - nsTransactionReleaseFunctor mRF; nsDeque mQue; public: diff --git a/mozilla/htmlparser/src/CNavDTD.cpp b/mozilla/htmlparser/src/CNavDTD.cpp index 56eaf149cff..6f4f45aa2ee 100644 --- a/mozilla/htmlparser/src/CNavDTD.cpp +++ b/mozilla/htmlparser/src/CNavDTD.cpp @@ -4,7 +4,7 @@ * Version 1.0 (the "NPL"); you may not use this file except in * compliance with the NPL. You may obtain a copy of the NPL at * http://www.mozilla.org/NPL/ - * + * * Software distributed under the NPL is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL * for the specific language governing rights and limitations under the @@ -25,7 +25,7 @@ #include "nsIParser.h" #include "nsIHTMLContentSink.h" #include "nsScanner.h" -#include "nsVoidArray.h" +//#include "nsVoidArray.h" #include "nsTokenHandler.h" #include "nsIDTDDebug.h" #include "prenv.h" //this is here for debug reasons... @@ -48,15 +48,11 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID); static NS_DEFINE_IID(kClassIID, NS_INAVHTML_DTD_IID); -//static const char* kNullURL = "Error: Null URL given"; -//static const char* kNullFilename= "Error: Null filename given"; static const char* kNullToken = "Error: Null token given"; static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; static char* kVerificationDir = "c:/temp"; -static const char* kViewSourceCommand= "view-source"; static char gShowCRC=0; -static nsAutoString gEmpty; static eHTMLTags gFormElementTags[]= { eHTMLTag_button, eHTMLTag_fieldset, eHTMLTag_input, @@ -132,7 +128,7 @@ public: class CTagHandlerRegister { public: - CTagHandlerRegister() : mDeallocator(), mTagHandlerDeque(mDeallocator) { + CTagHandlerRegister() : mTagHandlerDeque(new CTagHandlerDeallocator()) { } ~CTagHandlerRegister() { @@ -151,7 +147,6 @@ public: return foundHandler; } - CTagHandlerDeallocator mDeallocator; nsDeque mTagHandlerDeque; CTagFinder mTagFinder; }; @@ -1208,6 +1203,7 @@ nsresult CNavDTD::HandleEndToken(CToken* aToken) { case eHTMLTag_map: case eHTMLTag_form: + case eHTMLTag_head: result=CloseContainer(theNode,theChildTag,PR_FALSE); break; @@ -1679,7 +1675,9 @@ PRBool CNavDTD::CanOmit(eHTMLTags aParent,eHTMLTags aChild) const { } CTagList* theParents=gHTMLElements[aChild].GetSpecialParents(); if(theParents) { - result=!theParents->Contains(aParent); + PRInt32 theParentIndex=theParents->GetTopmostIndexOf(mBodyContext->mTags); + result=PRBool(kNotFound==theParentIndex); + // result=!theParents->Contains(aParent); THE OLD WAY } } break; @@ -1727,21 +1725,6 @@ PRBool CNavDTD::CanOmitEndTag(eHTMLTags aParent,eHTMLTags aChild) const { return PR_TRUE; } -/* - CTagList* theRootTags=gHTMLElements[aChild].GetRootTags(); - if(theRootTags) { - PRInt32 theRootIndex=theRootTags->GetTopmostIndexOf(mBodyContext->mTags); - PRInt32 theChildIndex=GetTopmostIndexOf(aChild); - if(kNotFound==theChildIndex) { - CTagList* theSynTags=gHTMLElements[aChild].GetSynonymousTags(); //get the list of tags that THIS tag can close - if(theSynTags) { - theChildIndex=theSynTags->GetTopmostIndexOf(mBodyContext->mTags); - } - } - result=!PRBool(theRootIndexGetCount() > 0, kInvalidTagStackPos); nsresult result=NS_OK; - static CEndToken aToken(gEmpty); - nsCParserNode theNode(&aToken,mLineNumber); + nsAutoString theEmpty; + CEndToken theToken(theEmpty); + nsCParserNode theNode(&theToken,mLineNumber); if((anIndexGetCount()) && (anIndex>=0)) { while(mBodyContext->GetCount()>anIndex) { eHTMLTags theTag=mBodyContext->Last(); - aToken.SetTypeID(theTag); + theToken.SetTypeID(theTag); result=CloseContainer(theNode,aTag,aUpdateStyles); } } @@ -2476,10 +2458,11 @@ nsresult CNavDTD::CloseContainersTo(eHTMLTags aTag,PRBool aUpdateStyles){ nsresult CNavDTD::CloseTopmostContainer(){ NS_PRECONDITION(mBodyContext->GetCount() > 0, kInvalidTagStackPos); - CEndToken aToken(gEmpty); + nsAutoString theEmpty; + CEndToken theToken(theEmpty); eHTMLTags theTag=mBodyContext->Last(); - aToken.SetTypeID(theTag); - nsCParserNode theNode(&aToken,mLineNumber); + theToken.SetTypeID(theTag); + nsCParserNode theNode(&theToken,mLineNumber); return CloseContainer(theNode,theTag,PR_TRUE); } @@ -2527,8 +2510,7 @@ nsresult CNavDTD::AddHeadLeaf(const nsIParserNode& aNode){ return result; } - -static nsTagStack kPropagationStack; + /** * This method gets called to create a valid context stack @@ -2543,6 +2525,7 @@ static nsTagStack kPropagationStack; */ nsresult CNavDTD::CreateContextStackFor(eHTMLTags aChildTag){ + static nsTagStack kPropagationStack; kPropagationStack.Empty(); nsresult result=(nsresult)kContextMismatch; @@ -2588,7 +2571,8 @@ nsresult CNavDTD::CreateContextStackFor(eHTMLTags aChildTag){ //now, build up the stack according to the tags //you have that aren't in the stack... - static CStartToken theToken(gEmpty); + nsAutoString theEmpty; + CStartToken theToken(theEmpty); if(PR_TRUE==bResult){ while(kPropagationStack.mCount>0) { eHTMLTags theTag=kPropagationStack.Pop(); diff --git a/mozilla/htmlparser/src/COtherDTD.cpp b/mozilla/htmlparser/src/COtherDTD.cpp index 63ccf4fee34..a1b56fbbdec 100644 --- a/mozilla/htmlparser/src/COtherDTD.cpp +++ b/mozilla/htmlparser/src/COtherDTD.cpp @@ -58,13 +58,6 @@ static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID); static NS_DEFINE_IID(kClassIID, NS_IOtherHTML_DTD_IID); static NS_DEFINE_IID(kBaseClassIID, NS_INAVHTML_DTD_IID); -//static const char* kNullURL = "Error: Null URL given"; -//static const char* kNullFilename= "Error: Null filename given"; -//static const char* kNullTokenizer = "Error: Unable to construct tokenizer"; -//static const char* kNullToken = "Error: Null token given"; -//static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; - -static nsAutoString gEmpty; /** diff --git a/mozilla/htmlparser/src/CParserContext.cpp b/mozilla/htmlparser/src/CParserContext.cpp index fc85676bbe9..f7f284166ef 100644 --- a/mozilla/htmlparser/src/CParserContext.cpp +++ b/mozilla/htmlparser/src/CParserContext.cpp @@ -20,19 +20,6 @@ #include "CParserContext.h" #include "nsToken.h" -/* -class CTokenDeallocator: public nsDequeFunctor{ -public: - virtual void* operator()(void* anObject) { - CToken* aToken = (CToken*)anObject; - delete aToken; - return 0; - } -}; - -CTokenDeallocator gTokenDeallocator; - -*/ /** * Your friendly little constructor. Ok, it's not the friendly, but the only guy diff --git a/mozilla/htmlparser/src/CParserContext.h b/mozilla/htmlparser/src/CParserContext.h index 3e1fd7d699e..c966c6b8519 100644 --- a/mozilla/htmlparser/src/CParserContext.h +++ b/mozilla/htmlparser/src/CParserContext.h @@ -70,8 +70,6 @@ public: eStreamState mStreamListenerState; //this is really only here for debug purposes. PRBool mMultipart; eContextType mContextType; - - // nsDeque mTokenDeque; }; diff --git a/mozilla/htmlparser/src/CRtfDTD.cpp b/mozilla/htmlparser/src/CRtfDTD.cpp index ab73ca3fc49..df1220da0d6 100644 --- a/mozilla/htmlparser/src/CRtfDTD.cpp +++ b/mozilla/htmlparser/src/CRtfDTD.cpp @@ -58,10 +58,7 @@ static NS_DEFINE_IID(kClassIID, NS_RTF_DTD_IID); static const char* kRTFTextContentType = "application/rtf"; static const char* kRTFDocHeader= "{\\rtf0"; -static nsString gAlphaChars("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); -static nsAutoString gDigits("-0123456789"); -static nsAutoString gEmpty; struct RTFEntry { char mName[10]; @@ -484,6 +481,9 @@ PRInt32 CRTFControlWord::GetTokenType() { PRInt32 CRTFControlWord::Consume(nsScanner& aScanner){ + static nsString gAlphaChars("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); + static nsAutoString gDigits("-0123456789"); + PRInt32 result=aScanner.ReadWhile(mTextValue,gAlphaChars,PR_TRUE,PR_FALSE); if(NS_OK==result) { //ok, now look for an option parameter... diff --git a/mozilla/htmlparser/src/nsDTDUtils.cpp b/mozilla/htmlparser/src/nsDTDUtils.cpp index 350ad994ab1..df84e866483 100644 --- a/mozilla/htmlparser/src/nsDTDUtils.cpp +++ b/mozilla/htmlparser/src/nsDTDUtils.cpp @@ -20,7 +20,6 @@ #include "nsDTDUtils.h" #include "CNavDTD.h" -static CTokenDeallocator gTokenKiller; /*************************************************************** First, define the tagstack class @@ -265,7 +264,7 @@ eHTMLTags nsDTDContext::Last() const { CTokenRecycler::CTokenRecycler() : nsITokenRecycler() { int i=0; for(i=0;iPop(); + + static nsAutoString theEmpty; + if(result) { + result->Reinitialize(aTag,theEmpty); + } + else { + //mTotals[aType-1]++; + switch(aType){ + case eToken_start: result=new CStartToken(aTag); break; + case eToken_end: result=new CEndToken(aTag); break; + case eToken_comment: result=new CCommentToken(); break; + case eToken_attribute: result=new CAttributeToken(); break; + case eToken_entity: result=new CEntityToken(); break; + case eToken_whitespace: result=new CWhitespaceToken(); break; + case eToken_newline: result=new CNewlineToken(); break; + case eToken_text: result=new CTextToken(theEmpty); break; + case eToken_script: result=new CScriptToken(); break; + case eToken_style: result=new CStyleToken(); break; + case eToken_skippedcontent: result=new CSkippedContentToken(theEmpty); break; + case eToken_instruction:result=new CInstructionToken(); break; + case eToken_cdatasection:result=new CCDATASectionToken(); break; + default: + break; + } + } + return result; +} + void DebugDumpContainmentRules(nsIDTD& theDTD,const char* aFilename,const char* aTitle) { const char* prefix=" "; fstream out(aFilename,ios::out); diff --git a/mozilla/htmlparser/src/nsDTDUtils.h b/mozilla/htmlparser/src/nsDTDUtils.h index 015998e5a43..1c2a70eaf60 100644 --- a/mozilla/htmlparser/src/nsDTDUtils.h +++ b/mozilla/htmlparser/src/nsDTDUtils.h @@ -144,6 +144,7 @@ public: virtual ~CTokenRecycler(); virtual void RecycleToken(CToken* aToken); virtual CToken* CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag, const nsString& aString); + virtual CToken* CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag); protected: nsDeque* mTokenCache[eToken_last-1]; diff --git a/mozilla/htmlparser/src/nsElementTable.cpp b/mozilla/htmlparser/src/nsElementTable.cpp index 8c98f374925..31dcc1001b0 100644 --- a/mozilla/htmlparser/src/nsElementTable.cpp +++ b/mozilla/htmlparser/src/nsElementTable.cpp @@ -44,13 +44,13 @@ PRBool CTagList::Contains(eHTMLTags aTag){ /** * * @update gess 01/04/99 - * @param + * @param * @return */ PRInt32 CTagList::GetTopmostIndexOf(nsTagStack& aTagStack){ int max=aTagStack.mCount; int index; - for(index=max-1;index>0;index--){ + for(index=max-1;index>=0;index--){ if(Contains(aTagStack.mTags[index])) { return index; } @@ -214,6 +214,7 @@ CTagList gNoframeRoot(2,0,eHTMLTag_body,eHTMLTag_frameset); CTagList gAutoClose(2,0,eHTMLTag_body,eHTMLTag_td); CTagList gBodyAutoClose(1,0,eHTMLTag_head); +CTagList gTBodyAutoClose(1,0,eHTMLTag_thead); CTagList gCaptionAutoClose(1,0,eHTMLTag_tbody); CTagList gLIAutoClose(2,0,eHTMLTag_p,eHTMLTag_li); CTagList gPAutoClose(2,0,eHTMLTag_p,eHTMLTag_li); @@ -442,7 +443,7 @@ nsHTMLElement gHTMLElements[] = { { /*tag*/ eHTMLTag_dl, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0, - /*parent,incl,exclgroups*/ kBlock, kSpecial, kNone, + /*parent,incl,exclgroups*/ kBlock, (kSpecial|kFontStyle), kNone, /*special properties*/ 0, /*special parents,kids,skip*/ 0,&gDLKids,eHTMLTag_unknown}, @@ -904,7 +905,7 @@ nsHTMLElement gHTMLElements[] = { { /*tag*/ eHTMLTag_tbody, /*rootnodes,endrootnodes*/ &gInTable, &gInTable, - /*autoclose starttags and endtags*/ 0,0,0, + /*autoclose starttags and endtags*/ &gTBodyAutoClose,0,0, /*parent,incl,exclgroups*/ kNone, kNone, kSelf, /*special properties*/ 0, /*special parents,kids,skip*/ &gInTable,&gTBodyKids,eHTMLTag_unknown}, diff --git a/mozilla/htmlparser/src/nsExpatDTD.cpp b/mozilla/htmlparser/src/nsExpatDTD.cpp index a45059d0bdf..844c16a491d 100644 --- a/mozilla/htmlparser/src/nsExpatDTD.cpp +++ b/mozilla/htmlparser/src/nsExpatDTD.cpp @@ -51,10 +51,6 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID); static NS_DEFINE_IID(kClassIID, NS_EXPAT_DTD_IID); -static const char* kViewSourceCommand= "view-source"; - - -static CTokenRecycler gTokenRecycler; /** diff --git a/mozilla/htmlparser/src/nsExpatTokenizer.cpp b/mozilla/htmlparser/src/nsExpatTokenizer.cpp index d2fea3bea0b..62c0a90f475 100644 --- a/mozilla/htmlparser/src/nsExpatTokenizer.cpp +++ b/mozilla/htmlparser/src/nsExpatTokenizer.cpp @@ -37,7 +37,6 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kITokenizerIID, NS_ITOKENIZER_IID); static NS_DEFINE_IID(kHTMLTokenizerIID, NS_HTMLTOKENIZER_IID); static NS_DEFINE_IID(kClassIID, NS_EXPATTOKENIZER_IID); -static nsAutoString gEmpty; /** * This method gets called as part of our COM-like interfaces. diff --git a/mozilla/htmlparser/src/nsHTMLTokenizer.cpp b/mozilla/htmlparser/src/nsHTMLTokenizer.cpp index 4a0ea68f9b9..5c8435ef68b 100644 --- a/mozilla/htmlparser/src/nsHTMLTokenizer.cpp +++ b/mozilla/htmlparser/src/nsHTMLTokenizer.cpp @@ -36,9 +36,7 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kITokenizerIID, NS_ITOKENIZER_IID); static NS_DEFINE_IID(kClassIID, NS_HTMLTOKENIZER_IID); -static CTokenDeallocator gTokenKiller; -static CTokenRecycler gTokenRecycler; -static nsAutoString gEmpty; +static CTokenRecycler* gTokenRecycler=0; /** * This method gets called as part of our COM-like interfaces. @@ -104,7 +102,7 @@ NS_IMPL_RELEASE(nsHTMLTokenizer) * @param * @return */ -nsHTMLTokenizer::nsHTMLTokenizer() : nsITokenizer(), mTokenDeque(gTokenKiller) { +nsHTMLTokenizer::nsHTMLTokenizer() : nsITokenizer(), mTokenDeque(new CTokenDeallocator()) { NS_INIT_REFCNT(); mDoXMLEmptyTags=PR_FALSE; } @@ -142,7 +140,8 @@ void AddToken(CToken*& aToken,nsresult aResult,nsDeque& aDeque) { * @return ptr to recycler (or null) */ nsITokenRecycler* nsHTMLTokenizer::GetTokenRecycler(void) { - return &gTokenRecycler; + gTokenRecycler=new CTokenRecycler(); + return gTokenRecycler; } @@ -332,7 +331,7 @@ nsresult nsHTMLTokenizer::ConsumeAttributes(PRUnichar aChar,CStartToken* aToken, CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler(); while((!done) && (result==NS_OK)) { - CToken* theToken= (CAttributeToken*)theRecycler->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,gEmpty); + CToken* theToken= (CAttributeToken*)theRecycler->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown); if(theToken){ result=theToken->Consume(aChar,aScanner); //tell new token to finish consuming text... @@ -452,7 +451,7 @@ nsresult nsHTMLTokenizer::ConsumeStartTag(PRUnichar aChar,CToken*& aToken,nsScan nsresult result=NS_OK; CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler(); - aToken=theRecycler->CreateTokenOfType(eToken_start,eHTMLTag_unknown,gEmpty); + aToken=theRecycler->CreateTokenOfType(eToken_start,eHTMLTag_unknown); if(aToken) { result= aToken->Consume(aChar,aScanner); //tell new token to finish consuming text... @@ -497,7 +496,7 @@ nsresult nsHTMLTokenizer::ConsumeStartTag(PRUnichar aChar,CToken*& aToken,nsScan nsresult nsHTMLTokenizer::ConsumeEndTag(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner) { CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler(); - aToken=theRecycler->CreateTokenOfType(eToken_end,eHTMLTag_unknown,gEmpty); + aToken=theRecycler->CreateTokenOfType(eToken_end,eHTMLTag_unknown); nsresult result=NS_OK; if(aToken) { @@ -524,11 +523,11 @@ nsresult nsHTMLTokenizer::ConsumeEntity(PRUnichar aChar,CToken*& aToken,nsScanne CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler(); if(NS_OK==result) { if(nsString::IsAlpha(theChar)) { //handle common enity references &xxx; or �. - aToken = theRecycler->CreateTokenOfType(eToken_entity,eHTMLTag_entity,gEmpty); + aToken = theRecycler->CreateTokenOfType(eToken_entity,eHTMLTag_entity); result = aToken->Consume(theChar,aScanner); //tell new token to finish consuming text... } else if(kHashsign==theChar) { - aToken = theRecycler->CreateTokenOfType(eToken_entity,eHTMLTag_entity,gEmpty); + aToken = theRecycler->CreateTokenOfType(eToken_entity,eHTMLTag_entity); result=aToken->Consume(0,aScanner); } else { @@ -555,7 +554,7 @@ nsresult nsHTMLTokenizer::ConsumeEntity(PRUnichar aChar,CToken*& aToken,nsScanne */ nsresult nsHTMLTokenizer::ConsumeWhitespace(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner) { CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler(); - aToken = theRecycler->CreateTokenOfType(eToken_whitespace,eHTMLTag_whitespace,gEmpty); + aToken = theRecycler->CreateTokenOfType(eToken_whitespace,eHTMLTag_whitespace); nsresult result=NS_OK; if(aToken) { result=aToken->Consume(aChar,aScanner); @@ -576,7 +575,7 @@ nsresult nsHTMLTokenizer::ConsumeWhitespace(PRUnichar aChar,CToken*& aToken,nsSc */ nsresult nsHTMLTokenizer::ConsumeComment(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner){ CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler(); - aToken = theRecycler->CreateTokenOfType(eToken_comment,eHTMLTag_comment,gEmpty); + aToken = theRecycler->CreateTokenOfType(eToken_comment,eHTMLTag_comment); nsresult result=NS_OK; if(aToken) { result=aToken->Consume(aChar,aScanner); @@ -626,7 +625,7 @@ nsresult nsHTMLTokenizer::ConsumeText(const nsString& aString,CToken*& aToken,ns */ nsresult nsHTMLTokenizer::ConsumeNewline(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner){ CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler(); - aToken=theRecycler->CreateTokenOfType(eToken_newline,eHTMLTag_newline,gEmpty); + aToken=theRecycler->CreateTokenOfType(eToken_newline,eHTMLTag_newline); nsresult result=NS_OK; if(aToken) { result=aToken->Consume(aChar,aScanner); @@ -647,7 +646,7 @@ nsresult nsHTMLTokenizer::ConsumeNewline(PRUnichar aChar,CToken*& aToken,nsScann */ nsresult nsHTMLTokenizer::ConsumeProcessingInstruction(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner){ CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler(); - aToken=theRecycler->CreateTokenOfType(eToken_instruction,eHTMLTag_unknown,gEmpty); + aToken=theRecycler->CreateTokenOfType(eToken_instruction,eHTMLTag_unknown); nsresult result=NS_OK; if(aToken) { result=aToken->Consume(aChar,aScanner); diff --git a/mozilla/htmlparser/src/nsHTMLTokens.cpp b/mozilla/htmlparser/src/nsHTMLTokens.cpp index 74245c77364..8fd515327ae 100644 --- a/mozilla/htmlparser/src/nsHTMLTokens.cpp +++ b/mozilla/htmlparser/src/nsHTMLTokens.cpp @@ -35,11 +35,7 @@ #include "nsEntityEx.cpp" #endif -static nsString gIdentChars("-0123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"); -static nsAutoString gDigits("0123456789"); -static nsAutoString gWhitespace("\b\t "); static const char* gUserdefined = "userdefined"; -static const char* gEmpty = ""; const PRInt32 kMAXNAMELEN=10; @@ -203,6 +199,11 @@ PRBool CStartToken::IsEmpty(void) { return mEmpty; } +nsString& GetIdentChars(void) { + static nsString gIdentChars("-0123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"); + return gIdentChars; +} + /* * Consume the identifier portion of the start tag * @@ -219,7 +220,7 @@ nsresult CStartToken::Consume(PRUnichar aChar, nsScanner& aScanner) { //NOTE: We don't Consume the tag attributes here, nor do we eat the ">" mTextValue=aChar; - nsresult result=aScanner.ReadWhile(mTextValue,gIdentChars,PR_TRUE,PR_FALSE); + nsresult result=aScanner.ReadWhile(mTextValue,GetIdentChars(),PR_TRUE,PR_FALSE); char buffer[300]; mTextValue.ToCString(buffer,sizeof(buffer)-1); mTypeID = NS_TagToEnum(buffer); @@ -1045,6 +1046,7 @@ nsresult CAttributeToken::Consume(PRUnichar aChar, nsScanner& aScanner) { result=aScanner.GetChar(aChar); //skip the hash sign... if(NS_OK==result) { mTextKey=aChar; + static nsAutoString gDigits("0123456789"); result=aScanner.ReadWhile(mTextKey,gDigits,PR_TRUE,PR_FALSE); } } @@ -1186,8 +1188,8 @@ PRInt32 CWhitespaceToken::GetTokenType(void) { nsresult CWhitespaceToken::Consume(PRUnichar aChar, nsScanner& aScanner) { mTextValue=aChar; - - nsresult result=aScanner.ReadWhile(mTextValue,gWhitespace,PR_FALSE,PR_FALSE); + static nsAutoString theWhitespace("\b\t "); + nsresult result=aScanner.ReadWhile(mTextValue,theWhitespace,PR_FALSE,PR_FALSE); if(NS_OK==result) { mTextValue.StripChars("\r"); } @@ -1287,7 +1289,7 @@ PRInt32 CEntityToken::ConsumeEntity(PRUnichar aChar,nsString& aString,nsScanner& } } //if else { - result=aScanner.ReadWhile(aString,gIdentChars,PR_TRUE,PR_FALSE); + result=aScanner.ReadWhile(aString,GetIdentChars(),PR_TRUE,PR_FALSE); if(NS_OK==result) { result=aScanner.Peek(aChar); if(NS_OK==result) { @@ -1521,6 +1523,8 @@ nsresult CSkippedContentToken::Consume(PRUnichar aChar,nsScanner& aScanner) { //If we find either, just eat them. If we find text or a tag, then go to the //target endtag, or the start of another comment. + static nsAutoString theWhitespace2("\b\t "); + while((!done) && (NS_OK==result)) { result=aScanner.GetChar(aChar); if((NS_OK==result) && (kLessThan==aChar)) { @@ -1541,7 +1545,7 @@ nsresult CSkippedContentToken::Consume(PRUnichar aChar,nsScanner& aScanner) { result=aScanner.ReadUntil(temp,kGreaterThan,PR_TRUE); } } - else if(0<=gWhitespace.BinarySearch(aChar)) { + else if(0<=theWhitespace2.BinarySearch(aChar)) { static CWhitespaceToken theWS; result=theWS.Consume(aChar,aScanner); if(NS_OK==result) { @@ -1587,7 +1591,7 @@ const char* GetTagName(PRInt32 aTag) { if (0 == result) { if(aTag>=eHTMLTag_userdefined) result = gUserdefined; - else result= gEmpty; + else result=0; } return result; } diff --git a/mozilla/htmlparser/src/nsIParser.h b/mozilla/htmlparser/src/nsIParser.h index dd25f902d3d..a8b7cbdab89 100644 --- a/mozilla/htmlparser/src/nsIParser.h +++ b/mozilla/htmlparser/src/nsIParser.h @@ -224,5 +224,6 @@ const PRUnichar kNullCh = '\0'; #define kRDFTextContentType "text/rdf" #define kXIFTextContentType "text/xif" #define kPlainTextContentType "text/plain" +#define kViewSourceCommand "view-source" #endif diff --git a/mozilla/htmlparser/src/nsParser.cpp b/mozilla/htmlparser/src/nsParser.cpp index 40daa5c853e..2d6b29a8d6d 100644 --- a/mozilla/htmlparser/src/nsParser.cpp +++ b/mozilla/htmlparser/src/nsParser.cpp @@ -46,10 +46,6 @@ static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID); static const char* kNullURL = "Error: Null URL given"; static const char* kOnStartNotCalled = "Error: OnStartBinding() must be called before OnDataAvailable()"; static const char* kBadListenerInit = "Error: Parser's IStreamListener API was not setup correctly in constructor."; -static nsString kUnknownFilename("unknown"); -static nsString kEmptyString("unknown"); - -static const int gTransferBufferSize=4096; //size of the buffer used in moving data from iistream class CTokenDeallocator: public nsDequeFunctor{ @@ -61,7 +57,6 @@ public: } }; -CTokenDeallocator gTokenDeallocator2; class CDTDDeallocator: public nsDequeFunctor{ public: @@ -91,7 +86,7 @@ public: class CSharedParserObjects { public: - CSharedParserObjects() : mDeallocator(), mDTDDeque(mDeallocator) { + CSharedParserObjects() : mDTDDeque(new CDTDDeallocator()) { nsIDTD* theDTD; @@ -125,11 +120,10 @@ public: return 0; } - CDTDDeallocator mDeallocator; nsDeque mDTDDeque; }; -CSharedParserObjects gSharedParserObjects; +static CSharedParserObjects* gSharedParserObjects=0; //---------------------------------------- @@ -148,6 +142,9 @@ nsParser::nsParser(nsITokenObserver* anObserver) : mCommand(""), mUnusedInput("" mParserContext=0; mTokenObserver=anObserver; mDTDVerification=PR_FALSE; + if(!gSharedParserObjects) { + gSharedParserObjects = new CSharedParserObjects(); + } } @@ -273,7 +270,7 @@ nsIContentSink* nsParser::GetContentSink(void){ } /** - * Call this static method when you want to + * Call this method when you want to * register your dynamic DTD's with the parser. * * @update gess 01/04/99 @@ -281,16 +278,7 @@ nsIContentSink* nsParser::GetContentSink(void){ * @return nothing. */ void nsParser::RegisterDTD(nsIDTD* aDTD){ - -#ifdef rickgdebug - nsIDTD* rv=0; - NS_NewRTF_DTD(&rv); - gSharedParserObjects.RegisterDTD(rv); - NS_NewWellFormed_DTD(&rv); - gSharedParserObjects.RegisterDTD(rv); -#endif - - gSharedParserObjects.RegisterDTD(aDTD); + gSharedParserObjects->RegisterDTD(aDTD); } /** @@ -334,8 +322,8 @@ PRBool FindSuitableDTD( CParserContext& aParserContext,nsString& aCommand,nsStri if(aParserContext.mDTD->CanParse(aParserContext.mSourceType,aCommand,aBuffer,0)) return PR_TRUE; - nsDequeIterator b=gSharedParserObjects.mDTDDeque.Begin(); - nsDequeIterator e=gSharedParserObjects.mDTDDeque.End(); + nsDequeIterator b=gSharedParserObjects->mDTDDeque.Begin(); + nsDequeIterator e=gSharedParserObjects->mDTDDeque.End(); aParserContext.mAutoDetectStatus=eUnknownDetect; nsIDTD* theBestDTD=0; @@ -567,7 +555,8 @@ nsresult nsParser::Parse(fstream& aStream,PRBool aVerifyEnabled){ nsresult result=NS_ERROR_OUT_OF_MEMORY; //ok, time to create our tokenizer and begin the process - CParserContext* pc=new CParserContext(new nsScanner(kUnknownFilename,aStream,PR_FALSE),&aStream,0); + nsAutoString theUnknownFilename("unknown"); + CParserContext* pc=new CParserContext(new nsScanner(theUnknownFilename,aStream,PR_FALSE),&aStream,0); if(pc) { PushContext(*pc); pc->mSourceType=kHTMLTextContentType; diff --git a/mozilla/htmlparser/src/nsParserNode.cpp b/mozilla/htmlparser/src/nsParserNode.cpp index 36bfb4891b3..04314b99ff5 100644 --- a/mozilla/htmlparser/src/nsParserNode.cpp +++ b/mozilla/htmlparser/src/nsParserNode.cpp @@ -23,7 +23,7 @@ #include "nshtmlpars.h" #include "nsITokenizer.h" -const nsAutoString nsCParserNode::mEmptyString(""); +const nsString* nsCParserNode::mEmptyString=0; static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kClassIID, NS_PARSER_NODE_IID); @@ -38,6 +38,9 @@ static NS_DEFINE_IID(kIParserNodeIID, NS_IPARSER_NODE_IID); */ nsCParserNode::nsCParserNode(CToken* aToken,PRInt32 aLineNumber,nsITokenRecycler* aRecycler): nsIParserNode() { NS_INIT_REFCNT(); + if(!mEmptyString) { + mEmptyString=new nsString(""); //this is going to leak, but it's a singleton + } mAttributeCount=0; mLineNumber=aLineNumber; mToken=aToken; @@ -162,7 +165,7 @@ void nsCParserNode::SetSkippedContent(CToken* aToken){ * @return string ref containing node name */ const nsString& nsCParserNode::GetName() const { - return mEmptyString; + return *mEmptyString; // return mName; } @@ -191,7 +194,7 @@ const nsString& nsCParserNode::GetSkippedContent() const { if (nsnull != mSkippedContent) { return ((CSkippedContentToken*)mSkippedContent)->GetKey(); } - return mEmptyString; + return *mEmptyString; } /** @@ -246,7 +249,7 @@ const nsString& nsCParserNode::GetKeyAt(PRInt32 anIndex) const { CAttributeToken* tkn=(CAttributeToken*)(mAttributes[anIndex]); return tkn->GetKey(); } - return mEmptyString; + return *mEmptyString; } @@ -262,7 +265,7 @@ const nsString& nsCParserNode::GetValueAt(PRInt32 anIndex) const { if(anIndexGetStringValueXXX(); } - return mEmptyString; + return *mEmptyString; } diff --git a/mozilla/htmlparser/src/nsParserNode.h b/mozilla/htmlparser/src/nsParserNode.h index d7ef81d4f4b..ffb0fda3fad 100644 --- a/mozilla/htmlparser/src/nsParserNode.h +++ b/mozilla/htmlparser/src/nsParserNode.h @@ -174,7 +174,7 @@ class nsCParserNode : public nsIParserNode { // nsAutoString mName; - static const nsAutoString mEmptyString; + static const nsString* mEmptyString; }; diff --git a/mozilla/htmlparser/src/nsValidDTD.cpp b/mozilla/htmlparser/src/nsValidDTD.cpp index 5403ab722bf..f46b4f266fd 100644 --- a/mozilla/htmlparser/src/nsValidDTD.cpp +++ b/mozilla/htmlparser/src/nsValidDTD.cpp @@ -55,15 +55,6 @@ static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID); static NS_DEFINE_IID(kClassIID, NS_VALID_DTD_IID); -//static const char* kNullURL = "Error: Null URL given"; -//static const char* kNullFilename= "Error: Null filename given"; -//static const char* kNullTokenizer = "Error: Unable to construct tokenizer"; -//static const char* kNullToken = "Error: Null token given"; -//static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; - -static nsAutoString gEmpty; - - /** * This method gets called as part of our COM-like interfaces. * Its purpose is to create an interface to parser object diff --git a/mozilla/htmlparser/src/nsViewSourceHTML.cpp b/mozilla/htmlparser/src/nsViewSourceHTML.cpp index f740fd82361..a8e3f113936 100644 --- a/mozilla/htmlparser/src/nsViewSourceHTML.cpp +++ b/mozilla/htmlparser/src/nsViewSourceHTML.cpp @@ -52,16 +52,6 @@ static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID); static NS_DEFINE_IID(kClassIID, NS_VIEWSOURCE_HTML_IID); -//static const char* kNullURL = "Error: Null URL given"; -//static const char* kNullFilename= "Error: Null filename given"; -//static const char* kNullTokenizer = "Error: Unable to construct tokenizer"; -//static const char* kNullToken = "Error: Null token given"; -//static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; -static const char* kViewSourceCommand= "view-source"; - -static nsAutoString gEmpty; -static CTokenRecycler gTokenRecycler; - /** * This method gets called as part of our COM-like interfaces. @@ -120,8 +110,6 @@ NS_IMPL_ADDREF(CViewSourceHTML) NS_IMPL_RELEASE(CViewSourceHTML) -static CTokenDeallocator gTokenKiller; - void SetFont(const char* aFace,const char* aSize,PRBool aEnable,nsIContentSink& aSink) { if(aEnable){ @@ -176,7 +164,7 @@ void SetStyle(eHTMLTags theTag,PRBool aEnable,nsIContentSink& aSink) { * @param * @return */ -CViewSourceHTML::CViewSourceHTML() : nsIDTD(), mTokenDeque(gTokenKiller) { +CViewSourceHTML::CViewSourceHTML() : nsIDTD() { NS_INIT_REFCNT(); mParser=0; mSink=0; diff --git a/mozilla/htmlparser/src/nsViewSourceHTML.h b/mozilla/htmlparser/src/nsViewSourceHTML.h index 719d7c6f5d9..c85e097f1a4 100644 --- a/mozilla/htmlparser/src/nsViewSourceHTML.h +++ b/mozilla/htmlparser/src/nsViewSourceHTML.h @@ -31,8 +31,6 @@ #include "nsISupports.h" #include "nsHTMLTokens.h" #include "nshtmlpars.h" -#include "nsVoidArray.h" -#include "nsDeque.h" #include "nsIHTMLContentSink.h" #define NS_VIEWSOURCE_HTML_IID \ @@ -243,7 +241,6 @@ protected: nsIHTMLContentSink* mSink; nsString mFilename; PRInt32 mLineNumber; - nsDeque mTokenDeque; PRBool mIsHTML; nsITokenizer* mTokenizer; PRInt32 mHasOpenHead; diff --git a/mozilla/htmlparser/src/nsWellFormedDTD.cpp b/mozilla/htmlparser/src/nsWellFormedDTD.cpp index 33cb9318901..12fd485b7e0 100644 --- a/mozilla/htmlparser/src/nsWellFormedDTD.cpp +++ b/mozilla/htmlparser/src/nsWellFormedDTD.cpp @@ -52,17 +52,6 @@ static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID); static NS_DEFINE_IID(kClassIID, NS_WELLFORMED_DTD_IID); -//static const char* kNullURL = "Error: Null URL given"; -//static const char* kNullFilename= "Error: Null filename given"; -//static const char* kNullTokenizer = "Error: Unable to construct tokenizer"; -//static const char* kNullToken = "Error: Null token given"; -//static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; -static const char* kViewSourceCommand= "view-source"; - -static nsAutoString gEmpty; -static CTokenRecycler gTokenRecycler; - - /** * This method gets called as part of our COM-like interfaces. * Its purpose is to create an interface to parser object @@ -120,7 +109,7 @@ NS_IMPL_ADDREF(CWellFormedDTD) NS_IMPL_RELEASE(CWellFormedDTD) -static CTokenDeallocator gTokenKiller; +//static CTokenDeallocator gTokenKiller; /** * Default constructor @@ -129,7 +118,7 @@ static CTokenDeallocator gTokenKiller; * @param * @return */ -CWellFormedDTD::CWellFormedDTD() : nsIDTD(), mTokenDeque(gTokenKiller) { +CWellFormedDTD::CWellFormedDTD() : nsIDTD() { NS_INIT_REFCNT(); mParser=0; mSink=0; diff --git a/mozilla/htmlparser/src/nsWellFormedDTD.h b/mozilla/htmlparser/src/nsWellFormedDTD.h index a2560b9560f..af42d2f0f6d 100644 --- a/mozilla/htmlparser/src/nsWellFormedDTD.h +++ b/mozilla/htmlparser/src/nsWellFormedDTD.h @@ -31,8 +31,6 @@ #include "nsISupports.h" #include "nsHTMLTokens.h" #include "nshtmlpars.h" -#include "nsVoidArray.h" -#include "nsDeque.h" #include "nsIContentSink.h" #define NS_WELLFORMED_DTD_IID \ @@ -235,7 +233,6 @@ protected: nsIContentSink* mSink; nsString mFilename; PRInt32 mLineNumber; - nsDeque mTokenDeque; nsITokenizer* mTokenizer; }; diff --git a/mozilla/htmlparser/src/nsXIFDTD.cpp b/mozilla/htmlparser/src/nsXIFDTD.cpp index 7c8bec83f07..dace83a142a 100644 --- a/mozilla/htmlparser/src/nsXIFDTD.cpp +++ b/mozilla/htmlparser/src/nsXIFDTD.cpp @@ -43,8 +43,6 @@ static NS_DEFINE_IID(kClassIID, NS_XIF_DTD_IID); static const char* kNullToken = "Error: Null token given"; static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; static const char* kXIFDocHeader= ""; - -static nsAutoString gEmpty; struct nsXIFTagEntry { @@ -309,7 +307,6 @@ public: }; -static nsXIfTokenDeallocator gTokenKiller; /** * Default constructor @@ -318,7 +315,7 @@ static nsXIfTokenDeallocator gTokenKiller; * @param * @return */ -nsXIFDTD::nsXIFDTD() : nsIDTD(), mTokenDeque(gTokenKiller) { +nsXIFDTD::nsXIFDTD() : nsIDTD(){ NS_INIT_REFCNT(); mParser=0; mTokenizer=0; diff --git a/mozilla/htmlparser/src/nsXIFDTD.h b/mozilla/htmlparser/src/nsXIFDTD.h index 49d342f244d..7bdb8b04426 100644 --- a/mozilla/htmlparser/src/nsXIFDTD.h +++ b/mozilla/htmlparser/src/nsXIFDTD.h @@ -34,7 +34,6 @@ #include "nsIDTD.h" #include "nsIContentSink.h" #include "nsHTMLTokens.h" -#include "nsDeque.h" #include "nsVoidArray.h" #include @@ -533,7 +532,6 @@ protected: PRBool mHasOpenForm; PRBool mHasOpenMap; - nsDeque mTokenDeque; nsIDTDDebug* mDTDDebug; diff --git a/mozilla/htmlparser/src/nsXMLTokenizer.cpp b/mozilla/htmlparser/src/nsXMLTokenizer.cpp index de1f6dfb311..c72058ebabc 100644 --- a/mozilla/htmlparser/src/nsXMLTokenizer.cpp +++ b/mozilla/htmlparser/src/nsXMLTokenizer.cpp @@ -37,7 +37,6 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kITokenizerIID, NS_ITOKENIZER_IID); static NS_DEFINE_IID(kHTMLTokenizerIID, NS_HTMLTOKENIZER_IID); static NS_DEFINE_IID(kClassIID, NS_XMLTOKENIZER_IID); -static nsAutoString gEmpty; /** * This method gets called as part of our COM-like interfaces. @@ -199,12 +198,14 @@ nsresult nsXMLTokenizer::ConsumeComment(PRUnichar aChar,nsScanner& aScanner,CTok result = ConsumeConditional(aScanner, CDATAString, isCDATA); CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler(); + if (NS_OK == result) { + nsAutoString theEmpty; if (isCDATA) { - aToken=theRecycler->CreateTokenOfType(eToken_cdatasection,eHTMLTag_unknown,gEmpty); + aToken=theRecycler->CreateTokenOfType(eToken_cdatasection,eHTMLTag_unknown,theEmpty); } else { - aToken=theRecycler->CreateTokenOfType(eToken_comment,eHTMLTag_comment,gEmpty); + aToken=theRecycler->CreateTokenOfType(eToken_comment,eHTMLTag_comment,theEmpty); } } diff --git a/mozilla/layout/base/nsCSSFrameConstructor.cpp b/mozilla/layout/base/nsCSSFrameConstructor.cpp index 83822cc8a6d..bdafab7cfa5 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/base/nsCSSFrameConstructor.cpp @@ -341,7 +341,7 @@ class nsBenignFunctor: public nsDequeFunctor{ } }; -static nsBenignFunctor* gBenignFunctor = new nsBenignFunctor; +//static nsBenignFunctor* gBenignFunctor = new nsBenignFunctor; // Construct the outer, inner table frames and the children frames for the table. @@ -763,7 +763,7 @@ nsCSSFrameConstructor::ConstructTableRowFrame(nsIPresContext* aPresContext, aNewTopMostFrame = aNewRowFrame; } else { // construct an anonymous row group frame nsIFrame* groupFrame; - nsDeque* toDo = (aToDo) ? aToDo : new nsDeque(*gBenignFunctor); + nsDeque* toDo = (aToDo) ? aToDo : new nsDeque(0); rv = ConstructTableGroupFrame(aPresContext, aContent, aParentFrame, styleContext, aAbsoluteItems, PR_TRUE, aNewTopMostFrame, groupFrame, aFixedItems, aTableCreator, toDo); @@ -918,7 +918,7 @@ nsCSSFrameConstructor::ConstructTableCellFrame(nsIPresContext* aPresContext, aNewTopMostFrame = aNewCellFrame; } else { // construct anonymous row frame nsIFrame* rowFrame; - nsDeque toDo(*gBenignFunctor); + nsDeque toDo(0); rv = ConstructTableRowFrame(aPresContext, aContent, aParentFrame, aStyleContext, aAbsoluteItems, aNewTopMostFrame, rowFrame, aFixedItems, aTableCreator, &toDo); if (NS_SUCCEEDED(rv)) { diff --git a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp index 83822cc8a6d..bdafab7cfa5 100644 --- a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp @@ -341,7 +341,7 @@ class nsBenignFunctor: public nsDequeFunctor{ } }; -static nsBenignFunctor* gBenignFunctor = new nsBenignFunctor; +//static nsBenignFunctor* gBenignFunctor = new nsBenignFunctor; // Construct the outer, inner table frames and the children frames for the table. @@ -763,7 +763,7 @@ nsCSSFrameConstructor::ConstructTableRowFrame(nsIPresContext* aPresContext, aNewTopMostFrame = aNewRowFrame; } else { // construct an anonymous row group frame nsIFrame* groupFrame; - nsDeque* toDo = (aToDo) ? aToDo : new nsDeque(*gBenignFunctor); + nsDeque* toDo = (aToDo) ? aToDo : new nsDeque(0); rv = ConstructTableGroupFrame(aPresContext, aContent, aParentFrame, styleContext, aAbsoluteItems, PR_TRUE, aNewTopMostFrame, groupFrame, aFixedItems, aTableCreator, toDo); @@ -918,7 +918,7 @@ nsCSSFrameConstructor::ConstructTableCellFrame(nsIPresContext* aPresContext, aNewTopMostFrame = aNewCellFrame; } else { // construct anonymous row frame nsIFrame* rowFrame; - nsDeque toDo(*gBenignFunctor); + nsDeque toDo(0); rv = ConstructTableRowFrame(aPresContext, aContent, aParentFrame, aStyleContext, aAbsoluteItems, aNewTopMostFrame, rowFrame, aFixedItems, aTableCreator, &toDo); if (NS_SUCCEEDED(rv)) { diff --git a/mozilla/parser/htmlparser/src/CNavDTD.cpp b/mozilla/parser/htmlparser/src/CNavDTD.cpp index 56eaf149cff..6f4f45aa2ee 100644 --- a/mozilla/parser/htmlparser/src/CNavDTD.cpp +++ b/mozilla/parser/htmlparser/src/CNavDTD.cpp @@ -4,7 +4,7 @@ * Version 1.0 (the "NPL"); you may not use this file except in * compliance with the NPL. You may obtain a copy of the NPL at * http://www.mozilla.org/NPL/ - * + * * Software distributed under the NPL is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL * for the specific language governing rights and limitations under the @@ -25,7 +25,7 @@ #include "nsIParser.h" #include "nsIHTMLContentSink.h" #include "nsScanner.h" -#include "nsVoidArray.h" +//#include "nsVoidArray.h" #include "nsTokenHandler.h" #include "nsIDTDDebug.h" #include "prenv.h" //this is here for debug reasons... @@ -48,15 +48,11 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID); static NS_DEFINE_IID(kClassIID, NS_INAVHTML_DTD_IID); -//static const char* kNullURL = "Error: Null URL given"; -//static const char* kNullFilename= "Error: Null filename given"; static const char* kNullToken = "Error: Null token given"; static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; static char* kVerificationDir = "c:/temp"; -static const char* kViewSourceCommand= "view-source"; static char gShowCRC=0; -static nsAutoString gEmpty; static eHTMLTags gFormElementTags[]= { eHTMLTag_button, eHTMLTag_fieldset, eHTMLTag_input, @@ -132,7 +128,7 @@ public: class CTagHandlerRegister { public: - CTagHandlerRegister() : mDeallocator(), mTagHandlerDeque(mDeallocator) { + CTagHandlerRegister() : mTagHandlerDeque(new CTagHandlerDeallocator()) { } ~CTagHandlerRegister() { @@ -151,7 +147,6 @@ public: return foundHandler; } - CTagHandlerDeallocator mDeallocator; nsDeque mTagHandlerDeque; CTagFinder mTagFinder; }; @@ -1208,6 +1203,7 @@ nsresult CNavDTD::HandleEndToken(CToken* aToken) { case eHTMLTag_map: case eHTMLTag_form: + case eHTMLTag_head: result=CloseContainer(theNode,theChildTag,PR_FALSE); break; @@ -1679,7 +1675,9 @@ PRBool CNavDTD::CanOmit(eHTMLTags aParent,eHTMLTags aChild) const { } CTagList* theParents=gHTMLElements[aChild].GetSpecialParents(); if(theParents) { - result=!theParents->Contains(aParent); + PRInt32 theParentIndex=theParents->GetTopmostIndexOf(mBodyContext->mTags); + result=PRBool(kNotFound==theParentIndex); + // result=!theParents->Contains(aParent); THE OLD WAY } } break; @@ -1727,21 +1725,6 @@ PRBool CNavDTD::CanOmitEndTag(eHTMLTags aParent,eHTMLTags aChild) const { return PR_TRUE; } -/* - CTagList* theRootTags=gHTMLElements[aChild].GetRootTags(); - if(theRootTags) { - PRInt32 theRootIndex=theRootTags->GetTopmostIndexOf(mBodyContext->mTags); - PRInt32 theChildIndex=GetTopmostIndexOf(aChild); - if(kNotFound==theChildIndex) { - CTagList* theSynTags=gHTMLElements[aChild].GetSynonymousTags(); //get the list of tags that THIS tag can close - if(theSynTags) { - theChildIndex=theSynTags->GetTopmostIndexOf(mBodyContext->mTags); - } - } - result=!PRBool(theRootIndexGetCount() > 0, kInvalidTagStackPos); nsresult result=NS_OK; - static CEndToken aToken(gEmpty); - nsCParserNode theNode(&aToken,mLineNumber); + nsAutoString theEmpty; + CEndToken theToken(theEmpty); + nsCParserNode theNode(&theToken,mLineNumber); if((anIndexGetCount()) && (anIndex>=0)) { while(mBodyContext->GetCount()>anIndex) { eHTMLTags theTag=mBodyContext->Last(); - aToken.SetTypeID(theTag); + theToken.SetTypeID(theTag); result=CloseContainer(theNode,aTag,aUpdateStyles); } } @@ -2476,10 +2458,11 @@ nsresult CNavDTD::CloseContainersTo(eHTMLTags aTag,PRBool aUpdateStyles){ nsresult CNavDTD::CloseTopmostContainer(){ NS_PRECONDITION(mBodyContext->GetCount() > 0, kInvalidTagStackPos); - CEndToken aToken(gEmpty); + nsAutoString theEmpty; + CEndToken theToken(theEmpty); eHTMLTags theTag=mBodyContext->Last(); - aToken.SetTypeID(theTag); - nsCParserNode theNode(&aToken,mLineNumber); + theToken.SetTypeID(theTag); + nsCParserNode theNode(&theToken,mLineNumber); return CloseContainer(theNode,theTag,PR_TRUE); } @@ -2527,8 +2510,7 @@ nsresult CNavDTD::AddHeadLeaf(const nsIParserNode& aNode){ return result; } - -static nsTagStack kPropagationStack; + /** * This method gets called to create a valid context stack @@ -2543,6 +2525,7 @@ static nsTagStack kPropagationStack; */ nsresult CNavDTD::CreateContextStackFor(eHTMLTags aChildTag){ + static nsTagStack kPropagationStack; kPropagationStack.Empty(); nsresult result=(nsresult)kContextMismatch; @@ -2588,7 +2571,8 @@ nsresult CNavDTD::CreateContextStackFor(eHTMLTags aChildTag){ //now, build up the stack according to the tags //you have that aren't in the stack... - static CStartToken theToken(gEmpty); + nsAutoString theEmpty; + CStartToken theToken(theEmpty); if(PR_TRUE==bResult){ while(kPropagationStack.mCount>0) { eHTMLTags theTag=kPropagationStack.Pop(); diff --git a/mozilla/parser/htmlparser/src/COtherDTD.cpp b/mozilla/parser/htmlparser/src/COtherDTD.cpp index 63ccf4fee34..a1b56fbbdec 100644 --- a/mozilla/parser/htmlparser/src/COtherDTD.cpp +++ b/mozilla/parser/htmlparser/src/COtherDTD.cpp @@ -58,13 +58,6 @@ static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID); static NS_DEFINE_IID(kClassIID, NS_IOtherHTML_DTD_IID); static NS_DEFINE_IID(kBaseClassIID, NS_INAVHTML_DTD_IID); -//static const char* kNullURL = "Error: Null URL given"; -//static const char* kNullFilename= "Error: Null filename given"; -//static const char* kNullTokenizer = "Error: Unable to construct tokenizer"; -//static const char* kNullToken = "Error: Null token given"; -//static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; - -static nsAutoString gEmpty; /** diff --git a/mozilla/parser/htmlparser/src/CParserContext.cpp b/mozilla/parser/htmlparser/src/CParserContext.cpp index fc85676bbe9..f7f284166ef 100644 --- a/mozilla/parser/htmlparser/src/CParserContext.cpp +++ b/mozilla/parser/htmlparser/src/CParserContext.cpp @@ -20,19 +20,6 @@ #include "CParserContext.h" #include "nsToken.h" -/* -class CTokenDeallocator: public nsDequeFunctor{ -public: - virtual void* operator()(void* anObject) { - CToken* aToken = (CToken*)anObject; - delete aToken; - return 0; - } -}; - -CTokenDeallocator gTokenDeallocator; - -*/ /** * Your friendly little constructor. Ok, it's not the friendly, but the only guy diff --git a/mozilla/parser/htmlparser/src/CParserContext.h b/mozilla/parser/htmlparser/src/CParserContext.h index 3e1fd7d699e..c966c6b8519 100644 --- a/mozilla/parser/htmlparser/src/CParserContext.h +++ b/mozilla/parser/htmlparser/src/CParserContext.h @@ -70,8 +70,6 @@ public: eStreamState mStreamListenerState; //this is really only here for debug purposes. PRBool mMultipart; eContextType mContextType; - - // nsDeque mTokenDeque; }; diff --git a/mozilla/parser/htmlparser/src/CRtfDTD.cpp b/mozilla/parser/htmlparser/src/CRtfDTD.cpp index ab73ca3fc49..df1220da0d6 100644 --- a/mozilla/parser/htmlparser/src/CRtfDTD.cpp +++ b/mozilla/parser/htmlparser/src/CRtfDTD.cpp @@ -58,10 +58,7 @@ static NS_DEFINE_IID(kClassIID, NS_RTF_DTD_IID); static const char* kRTFTextContentType = "application/rtf"; static const char* kRTFDocHeader= "{\\rtf0"; -static nsString gAlphaChars("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); -static nsAutoString gDigits("-0123456789"); -static nsAutoString gEmpty; struct RTFEntry { char mName[10]; @@ -484,6 +481,9 @@ PRInt32 CRTFControlWord::GetTokenType() { PRInt32 CRTFControlWord::Consume(nsScanner& aScanner){ + static nsString gAlphaChars("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); + static nsAutoString gDigits("-0123456789"); + PRInt32 result=aScanner.ReadWhile(mTextValue,gAlphaChars,PR_TRUE,PR_FALSE); if(NS_OK==result) { //ok, now look for an option parameter... diff --git a/mozilla/parser/htmlparser/src/nsDTDUtils.cpp b/mozilla/parser/htmlparser/src/nsDTDUtils.cpp index 350ad994ab1..df84e866483 100644 --- a/mozilla/parser/htmlparser/src/nsDTDUtils.cpp +++ b/mozilla/parser/htmlparser/src/nsDTDUtils.cpp @@ -20,7 +20,6 @@ #include "nsDTDUtils.h" #include "CNavDTD.h" -static CTokenDeallocator gTokenKiller; /*************************************************************** First, define the tagstack class @@ -265,7 +264,7 @@ eHTMLTags nsDTDContext::Last() const { CTokenRecycler::CTokenRecycler() : nsITokenRecycler() { int i=0; for(i=0;iPop(); + + static nsAutoString theEmpty; + if(result) { + result->Reinitialize(aTag,theEmpty); + } + else { + //mTotals[aType-1]++; + switch(aType){ + case eToken_start: result=new CStartToken(aTag); break; + case eToken_end: result=new CEndToken(aTag); break; + case eToken_comment: result=new CCommentToken(); break; + case eToken_attribute: result=new CAttributeToken(); break; + case eToken_entity: result=new CEntityToken(); break; + case eToken_whitespace: result=new CWhitespaceToken(); break; + case eToken_newline: result=new CNewlineToken(); break; + case eToken_text: result=new CTextToken(theEmpty); break; + case eToken_script: result=new CScriptToken(); break; + case eToken_style: result=new CStyleToken(); break; + case eToken_skippedcontent: result=new CSkippedContentToken(theEmpty); break; + case eToken_instruction:result=new CInstructionToken(); break; + case eToken_cdatasection:result=new CCDATASectionToken(); break; + default: + break; + } + } + return result; +} + void DebugDumpContainmentRules(nsIDTD& theDTD,const char* aFilename,const char* aTitle) { const char* prefix=" "; fstream out(aFilename,ios::out); diff --git a/mozilla/parser/htmlparser/src/nsDTDUtils.h b/mozilla/parser/htmlparser/src/nsDTDUtils.h index 015998e5a43..1c2a70eaf60 100644 --- a/mozilla/parser/htmlparser/src/nsDTDUtils.h +++ b/mozilla/parser/htmlparser/src/nsDTDUtils.h @@ -144,6 +144,7 @@ public: virtual ~CTokenRecycler(); virtual void RecycleToken(CToken* aToken); virtual CToken* CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag, const nsString& aString); + virtual CToken* CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag); protected: nsDeque* mTokenCache[eToken_last-1]; diff --git a/mozilla/parser/htmlparser/src/nsElementTable.cpp b/mozilla/parser/htmlparser/src/nsElementTable.cpp index 8c98f374925..31dcc1001b0 100644 --- a/mozilla/parser/htmlparser/src/nsElementTable.cpp +++ b/mozilla/parser/htmlparser/src/nsElementTable.cpp @@ -44,13 +44,13 @@ PRBool CTagList::Contains(eHTMLTags aTag){ /** * * @update gess 01/04/99 - * @param + * @param * @return */ PRInt32 CTagList::GetTopmostIndexOf(nsTagStack& aTagStack){ int max=aTagStack.mCount; int index; - for(index=max-1;index>0;index--){ + for(index=max-1;index>=0;index--){ if(Contains(aTagStack.mTags[index])) { return index; } @@ -214,6 +214,7 @@ CTagList gNoframeRoot(2,0,eHTMLTag_body,eHTMLTag_frameset); CTagList gAutoClose(2,0,eHTMLTag_body,eHTMLTag_td); CTagList gBodyAutoClose(1,0,eHTMLTag_head); +CTagList gTBodyAutoClose(1,0,eHTMLTag_thead); CTagList gCaptionAutoClose(1,0,eHTMLTag_tbody); CTagList gLIAutoClose(2,0,eHTMLTag_p,eHTMLTag_li); CTagList gPAutoClose(2,0,eHTMLTag_p,eHTMLTag_li); @@ -442,7 +443,7 @@ nsHTMLElement gHTMLElements[] = { { /*tag*/ eHTMLTag_dl, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0, - /*parent,incl,exclgroups*/ kBlock, kSpecial, kNone, + /*parent,incl,exclgroups*/ kBlock, (kSpecial|kFontStyle), kNone, /*special properties*/ 0, /*special parents,kids,skip*/ 0,&gDLKids,eHTMLTag_unknown}, @@ -904,7 +905,7 @@ nsHTMLElement gHTMLElements[] = { { /*tag*/ eHTMLTag_tbody, /*rootnodes,endrootnodes*/ &gInTable, &gInTable, - /*autoclose starttags and endtags*/ 0,0,0, + /*autoclose starttags and endtags*/ &gTBodyAutoClose,0,0, /*parent,incl,exclgroups*/ kNone, kNone, kSelf, /*special properties*/ 0, /*special parents,kids,skip*/ &gInTable,&gTBodyKids,eHTMLTag_unknown}, diff --git a/mozilla/parser/htmlparser/src/nsExpatDTD.cpp b/mozilla/parser/htmlparser/src/nsExpatDTD.cpp index a45059d0bdf..844c16a491d 100644 --- a/mozilla/parser/htmlparser/src/nsExpatDTD.cpp +++ b/mozilla/parser/htmlparser/src/nsExpatDTD.cpp @@ -51,10 +51,6 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID); static NS_DEFINE_IID(kClassIID, NS_EXPAT_DTD_IID); -static const char* kViewSourceCommand= "view-source"; - - -static CTokenRecycler gTokenRecycler; /** diff --git a/mozilla/parser/htmlparser/src/nsExpatTokenizer.cpp b/mozilla/parser/htmlparser/src/nsExpatTokenizer.cpp index d2fea3bea0b..62c0a90f475 100644 --- a/mozilla/parser/htmlparser/src/nsExpatTokenizer.cpp +++ b/mozilla/parser/htmlparser/src/nsExpatTokenizer.cpp @@ -37,7 +37,6 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kITokenizerIID, NS_ITOKENIZER_IID); static NS_DEFINE_IID(kHTMLTokenizerIID, NS_HTMLTOKENIZER_IID); static NS_DEFINE_IID(kClassIID, NS_EXPATTOKENIZER_IID); -static nsAutoString gEmpty; /** * This method gets called as part of our COM-like interfaces. diff --git a/mozilla/parser/htmlparser/src/nsHTMLTokenizer.cpp b/mozilla/parser/htmlparser/src/nsHTMLTokenizer.cpp index 4a0ea68f9b9..5c8435ef68b 100644 --- a/mozilla/parser/htmlparser/src/nsHTMLTokenizer.cpp +++ b/mozilla/parser/htmlparser/src/nsHTMLTokenizer.cpp @@ -36,9 +36,7 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kITokenizerIID, NS_ITOKENIZER_IID); static NS_DEFINE_IID(kClassIID, NS_HTMLTOKENIZER_IID); -static CTokenDeallocator gTokenKiller; -static CTokenRecycler gTokenRecycler; -static nsAutoString gEmpty; +static CTokenRecycler* gTokenRecycler=0; /** * This method gets called as part of our COM-like interfaces. @@ -104,7 +102,7 @@ NS_IMPL_RELEASE(nsHTMLTokenizer) * @param * @return */ -nsHTMLTokenizer::nsHTMLTokenizer() : nsITokenizer(), mTokenDeque(gTokenKiller) { +nsHTMLTokenizer::nsHTMLTokenizer() : nsITokenizer(), mTokenDeque(new CTokenDeallocator()) { NS_INIT_REFCNT(); mDoXMLEmptyTags=PR_FALSE; } @@ -142,7 +140,8 @@ void AddToken(CToken*& aToken,nsresult aResult,nsDeque& aDeque) { * @return ptr to recycler (or null) */ nsITokenRecycler* nsHTMLTokenizer::GetTokenRecycler(void) { - return &gTokenRecycler; + gTokenRecycler=new CTokenRecycler(); + return gTokenRecycler; } @@ -332,7 +331,7 @@ nsresult nsHTMLTokenizer::ConsumeAttributes(PRUnichar aChar,CStartToken* aToken, CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler(); while((!done) && (result==NS_OK)) { - CToken* theToken= (CAttributeToken*)theRecycler->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,gEmpty); + CToken* theToken= (CAttributeToken*)theRecycler->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown); if(theToken){ result=theToken->Consume(aChar,aScanner); //tell new token to finish consuming text... @@ -452,7 +451,7 @@ nsresult nsHTMLTokenizer::ConsumeStartTag(PRUnichar aChar,CToken*& aToken,nsScan nsresult result=NS_OK; CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler(); - aToken=theRecycler->CreateTokenOfType(eToken_start,eHTMLTag_unknown,gEmpty); + aToken=theRecycler->CreateTokenOfType(eToken_start,eHTMLTag_unknown); if(aToken) { result= aToken->Consume(aChar,aScanner); //tell new token to finish consuming text... @@ -497,7 +496,7 @@ nsresult nsHTMLTokenizer::ConsumeStartTag(PRUnichar aChar,CToken*& aToken,nsScan nsresult nsHTMLTokenizer::ConsumeEndTag(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner) { CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler(); - aToken=theRecycler->CreateTokenOfType(eToken_end,eHTMLTag_unknown,gEmpty); + aToken=theRecycler->CreateTokenOfType(eToken_end,eHTMLTag_unknown); nsresult result=NS_OK; if(aToken) { @@ -524,11 +523,11 @@ nsresult nsHTMLTokenizer::ConsumeEntity(PRUnichar aChar,CToken*& aToken,nsScanne CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler(); if(NS_OK==result) { if(nsString::IsAlpha(theChar)) { //handle common enity references &xxx; or �. - aToken = theRecycler->CreateTokenOfType(eToken_entity,eHTMLTag_entity,gEmpty); + aToken = theRecycler->CreateTokenOfType(eToken_entity,eHTMLTag_entity); result = aToken->Consume(theChar,aScanner); //tell new token to finish consuming text... } else if(kHashsign==theChar) { - aToken = theRecycler->CreateTokenOfType(eToken_entity,eHTMLTag_entity,gEmpty); + aToken = theRecycler->CreateTokenOfType(eToken_entity,eHTMLTag_entity); result=aToken->Consume(0,aScanner); } else { @@ -555,7 +554,7 @@ nsresult nsHTMLTokenizer::ConsumeEntity(PRUnichar aChar,CToken*& aToken,nsScanne */ nsresult nsHTMLTokenizer::ConsumeWhitespace(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner) { CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler(); - aToken = theRecycler->CreateTokenOfType(eToken_whitespace,eHTMLTag_whitespace,gEmpty); + aToken = theRecycler->CreateTokenOfType(eToken_whitespace,eHTMLTag_whitespace); nsresult result=NS_OK; if(aToken) { result=aToken->Consume(aChar,aScanner); @@ -576,7 +575,7 @@ nsresult nsHTMLTokenizer::ConsumeWhitespace(PRUnichar aChar,CToken*& aToken,nsSc */ nsresult nsHTMLTokenizer::ConsumeComment(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner){ CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler(); - aToken = theRecycler->CreateTokenOfType(eToken_comment,eHTMLTag_comment,gEmpty); + aToken = theRecycler->CreateTokenOfType(eToken_comment,eHTMLTag_comment); nsresult result=NS_OK; if(aToken) { result=aToken->Consume(aChar,aScanner); @@ -626,7 +625,7 @@ nsresult nsHTMLTokenizer::ConsumeText(const nsString& aString,CToken*& aToken,ns */ nsresult nsHTMLTokenizer::ConsumeNewline(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner){ CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler(); - aToken=theRecycler->CreateTokenOfType(eToken_newline,eHTMLTag_newline,gEmpty); + aToken=theRecycler->CreateTokenOfType(eToken_newline,eHTMLTag_newline); nsresult result=NS_OK; if(aToken) { result=aToken->Consume(aChar,aScanner); @@ -647,7 +646,7 @@ nsresult nsHTMLTokenizer::ConsumeNewline(PRUnichar aChar,CToken*& aToken,nsScann */ nsresult nsHTMLTokenizer::ConsumeProcessingInstruction(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner){ CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler(); - aToken=theRecycler->CreateTokenOfType(eToken_instruction,eHTMLTag_unknown,gEmpty); + aToken=theRecycler->CreateTokenOfType(eToken_instruction,eHTMLTag_unknown); nsresult result=NS_OK; if(aToken) { result=aToken->Consume(aChar,aScanner); diff --git a/mozilla/parser/htmlparser/src/nsHTMLTokens.cpp b/mozilla/parser/htmlparser/src/nsHTMLTokens.cpp index 74245c77364..8fd515327ae 100644 --- a/mozilla/parser/htmlparser/src/nsHTMLTokens.cpp +++ b/mozilla/parser/htmlparser/src/nsHTMLTokens.cpp @@ -35,11 +35,7 @@ #include "nsEntityEx.cpp" #endif -static nsString gIdentChars("-0123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"); -static nsAutoString gDigits("0123456789"); -static nsAutoString gWhitespace("\b\t "); static const char* gUserdefined = "userdefined"; -static const char* gEmpty = ""; const PRInt32 kMAXNAMELEN=10; @@ -203,6 +199,11 @@ PRBool CStartToken::IsEmpty(void) { return mEmpty; } +nsString& GetIdentChars(void) { + static nsString gIdentChars("-0123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"); + return gIdentChars; +} + /* * Consume the identifier portion of the start tag * @@ -219,7 +220,7 @@ nsresult CStartToken::Consume(PRUnichar aChar, nsScanner& aScanner) { //NOTE: We don't Consume the tag attributes here, nor do we eat the ">" mTextValue=aChar; - nsresult result=aScanner.ReadWhile(mTextValue,gIdentChars,PR_TRUE,PR_FALSE); + nsresult result=aScanner.ReadWhile(mTextValue,GetIdentChars(),PR_TRUE,PR_FALSE); char buffer[300]; mTextValue.ToCString(buffer,sizeof(buffer)-1); mTypeID = NS_TagToEnum(buffer); @@ -1045,6 +1046,7 @@ nsresult CAttributeToken::Consume(PRUnichar aChar, nsScanner& aScanner) { result=aScanner.GetChar(aChar); //skip the hash sign... if(NS_OK==result) { mTextKey=aChar; + static nsAutoString gDigits("0123456789"); result=aScanner.ReadWhile(mTextKey,gDigits,PR_TRUE,PR_FALSE); } } @@ -1186,8 +1188,8 @@ PRInt32 CWhitespaceToken::GetTokenType(void) { nsresult CWhitespaceToken::Consume(PRUnichar aChar, nsScanner& aScanner) { mTextValue=aChar; - - nsresult result=aScanner.ReadWhile(mTextValue,gWhitespace,PR_FALSE,PR_FALSE); + static nsAutoString theWhitespace("\b\t "); + nsresult result=aScanner.ReadWhile(mTextValue,theWhitespace,PR_FALSE,PR_FALSE); if(NS_OK==result) { mTextValue.StripChars("\r"); } @@ -1287,7 +1289,7 @@ PRInt32 CEntityToken::ConsumeEntity(PRUnichar aChar,nsString& aString,nsScanner& } } //if else { - result=aScanner.ReadWhile(aString,gIdentChars,PR_TRUE,PR_FALSE); + result=aScanner.ReadWhile(aString,GetIdentChars(),PR_TRUE,PR_FALSE); if(NS_OK==result) { result=aScanner.Peek(aChar); if(NS_OK==result) { @@ -1521,6 +1523,8 @@ nsresult CSkippedContentToken::Consume(PRUnichar aChar,nsScanner& aScanner) { //If we find either, just eat them. If we find text or a tag, then go to the //target endtag, or the start of another comment. + static nsAutoString theWhitespace2("\b\t "); + while((!done) && (NS_OK==result)) { result=aScanner.GetChar(aChar); if((NS_OK==result) && (kLessThan==aChar)) { @@ -1541,7 +1545,7 @@ nsresult CSkippedContentToken::Consume(PRUnichar aChar,nsScanner& aScanner) { result=aScanner.ReadUntil(temp,kGreaterThan,PR_TRUE); } } - else if(0<=gWhitespace.BinarySearch(aChar)) { + else if(0<=theWhitespace2.BinarySearch(aChar)) { static CWhitespaceToken theWS; result=theWS.Consume(aChar,aScanner); if(NS_OK==result) { @@ -1587,7 +1591,7 @@ const char* GetTagName(PRInt32 aTag) { if (0 == result) { if(aTag>=eHTMLTag_userdefined) result = gUserdefined; - else result= gEmpty; + else result=0; } return result; } diff --git a/mozilla/parser/htmlparser/src/nsIParser.h b/mozilla/parser/htmlparser/src/nsIParser.h index dd25f902d3d..a8b7cbdab89 100644 --- a/mozilla/parser/htmlparser/src/nsIParser.h +++ b/mozilla/parser/htmlparser/src/nsIParser.h @@ -224,5 +224,6 @@ const PRUnichar kNullCh = '\0'; #define kRDFTextContentType "text/rdf" #define kXIFTextContentType "text/xif" #define kPlainTextContentType "text/plain" +#define kViewSourceCommand "view-source" #endif diff --git a/mozilla/parser/htmlparser/src/nsParser.cpp b/mozilla/parser/htmlparser/src/nsParser.cpp index 40daa5c853e..2d6b29a8d6d 100644 --- a/mozilla/parser/htmlparser/src/nsParser.cpp +++ b/mozilla/parser/htmlparser/src/nsParser.cpp @@ -46,10 +46,6 @@ static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID); static const char* kNullURL = "Error: Null URL given"; static const char* kOnStartNotCalled = "Error: OnStartBinding() must be called before OnDataAvailable()"; static const char* kBadListenerInit = "Error: Parser's IStreamListener API was not setup correctly in constructor."; -static nsString kUnknownFilename("unknown"); -static nsString kEmptyString("unknown"); - -static const int gTransferBufferSize=4096; //size of the buffer used in moving data from iistream class CTokenDeallocator: public nsDequeFunctor{ @@ -61,7 +57,6 @@ public: } }; -CTokenDeallocator gTokenDeallocator2; class CDTDDeallocator: public nsDequeFunctor{ public: @@ -91,7 +86,7 @@ public: class CSharedParserObjects { public: - CSharedParserObjects() : mDeallocator(), mDTDDeque(mDeallocator) { + CSharedParserObjects() : mDTDDeque(new CDTDDeallocator()) { nsIDTD* theDTD; @@ -125,11 +120,10 @@ public: return 0; } - CDTDDeallocator mDeallocator; nsDeque mDTDDeque; }; -CSharedParserObjects gSharedParserObjects; +static CSharedParserObjects* gSharedParserObjects=0; //---------------------------------------- @@ -148,6 +142,9 @@ nsParser::nsParser(nsITokenObserver* anObserver) : mCommand(""), mUnusedInput("" mParserContext=0; mTokenObserver=anObserver; mDTDVerification=PR_FALSE; + if(!gSharedParserObjects) { + gSharedParserObjects = new CSharedParserObjects(); + } } @@ -273,7 +270,7 @@ nsIContentSink* nsParser::GetContentSink(void){ } /** - * Call this static method when you want to + * Call this method when you want to * register your dynamic DTD's with the parser. * * @update gess 01/04/99 @@ -281,16 +278,7 @@ nsIContentSink* nsParser::GetContentSink(void){ * @return nothing. */ void nsParser::RegisterDTD(nsIDTD* aDTD){ - -#ifdef rickgdebug - nsIDTD* rv=0; - NS_NewRTF_DTD(&rv); - gSharedParserObjects.RegisterDTD(rv); - NS_NewWellFormed_DTD(&rv); - gSharedParserObjects.RegisterDTD(rv); -#endif - - gSharedParserObjects.RegisterDTD(aDTD); + gSharedParserObjects->RegisterDTD(aDTD); } /** @@ -334,8 +322,8 @@ PRBool FindSuitableDTD( CParserContext& aParserContext,nsString& aCommand,nsStri if(aParserContext.mDTD->CanParse(aParserContext.mSourceType,aCommand,aBuffer,0)) return PR_TRUE; - nsDequeIterator b=gSharedParserObjects.mDTDDeque.Begin(); - nsDequeIterator e=gSharedParserObjects.mDTDDeque.End(); + nsDequeIterator b=gSharedParserObjects->mDTDDeque.Begin(); + nsDequeIterator e=gSharedParserObjects->mDTDDeque.End(); aParserContext.mAutoDetectStatus=eUnknownDetect; nsIDTD* theBestDTD=0; @@ -567,7 +555,8 @@ nsresult nsParser::Parse(fstream& aStream,PRBool aVerifyEnabled){ nsresult result=NS_ERROR_OUT_OF_MEMORY; //ok, time to create our tokenizer and begin the process - CParserContext* pc=new CParserContext(new nsScanner(kUnknownFilename,aStream,PR_FALSE),&aStream,0); + nsAutoString theUnknownFilename("unknown"); + CParserContext* pc=new CParserContext(new nsScanner(theUnknownFilename,aStream,PR_FALSE),&aStream,0); if(pc) { PushContext(*pc); pc->mSourceType=kHTMLTextContentType; diff --git a/mozilla/parser/htmlparser/src/nsParserNode.cpp b/mozilla/parser/htmlparser/src/nsParserNode.cpp index 36bfb4891b3..04314b99ff5 100644 --- a/mozilla/parser/htmlparser/src/nsParserNode.cpp +++ b/mozilla/parser/htmlparser/src/nsParserNode.cpp @@ -23,7 +23,7 @@ #include "nshtmlpars.h" #include "nsITokenizer.h" -const nsAutoString nsCParserNode::mEmptyString(""); +const nsString* nsCParserNode::mEmptyString=0; static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kClassIID, NS_PARSER_NODE_IID); @@ -38,6 +38,9 @@ static NS_DEFINE_IID(kIParserNodeIID, NS_IPARSER_NODE_IID); */ nsCParserNode::nsCParserNode(CToken* aToken,PRInt32 aLineNumber,nsITokenRecycler* aRecycler): nsIParserNode() { NS_INIT_REFCNT(); + if(!mEmptyString) { + mEmptyString=new nsString(""); //this is going to leak, but it's a singleton + } mAttributeCount=0; mLineNumber=aLineNumber; mToken=aToken; @@ -162,7 +165,7 @@ void nsCParserNode::SetSkippedContent(CToken* aToken){ * @return string ref containing node name */ const nsString& nsCParserNode::GetName() const { - return mEmptyString; + return *mEmptyString; // return mName; } @@ -191,7 +194,7 @@ const nsString& nsCParserNode::GetSkippedContent() const { if (nsnull != mSkippedContent) { return ((CSkippedContentToken*)mSkippedContent)->GetKey(); } - return mEmptyString; + return *mEmptyString; } /** @@ -246,7 +249,7 @@ const nsString& nsCParserNode::GetKeyAt(PRInt32 anIndex) const { CAttributeToken* tkn=(CAttributeToken*)(mAttributes[anIndex]); return tkn->GetKey(); } - return mEmptyString; + return *mEmptyString; } @@ -262,7 +265,7 @@ const nsString& nsCParserNode::GetValueAt(PRInt32 anIndex) const { if(anIndexGetStringValueXXX(); } - return mEmptyString; + return *mEmptyString; } diff --git a/mozilla/parser/htmlparser/src/nsParserNode.h b/mozilla/parser/htmlparser/src/nsParserNode.h index d7ef81d4f4b..ffb0fda3fad 100644 --- a/mozilla/parser/htmlparser/src/nsParserNode.h +++ b/mozilla/parser/htmlparser/src/nsParserNode.h @@ -174,7 +174,7 @@ class nsCParserNode : public nsIParserNode { // nsAutoString mName; - static const nsAutoString mEmptyString; + static const nsString* mEmptyString; }; diff --git a/mozilla/parser/htmlparser/src/nsValidDTD.cpp b/mozilla/parser/htmlparser/src/nsValidDTD.cpp index 5403ab722bf..f46b4f266fd 100644 --- a/mozilla/parser/htmlparser/src/nsValidDTD.cpp +++ b/mozilla/parser/htmlparser/src/nsValidDTD.cpp @@ -55,15 +55,6 @@ static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID); static NS_DEFINE_IID(kClassIID, NS_VALID_DTD_IID); -//static const char* kNullURL = "Error: Null URL given"; -//static const char* kNullFilename= "Error: Null filename given"; -//static const char* kNullTokenizer = "Error: Unable to construct tokenizer"; -//static const char* kNullToken = "Error: Null token given"; -//static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; - -static nsAutoString gEmpty; - - /** * This method gets called as part of our COM-like interfaces. * Its purpose is to create an interface to parser object diff --git a/mozilla/parser/htmlparser/src/nsViewSourceHTML.cpp b/mozilla/parser/htmlparser/src/nsViewSourceHTML.cpp index f740fd82361..a8e3f113936 100644 --- a/mozilla/parser/htmlparser/src/nsViewSourceHTML.cpp +++ b/mozilla/parser/htmlparser/src/nsViewSourceHTML.cpp @@ -52,16 +52,6 @@ static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID); static NS_DEFINE_IID(kClassIID, NS_VIEWSOURCE_HTML_IID); -//static const char* kNullURL = "Error: Null URL given"; -//static const char* kNullFilename= "Error: Null filename given"; -//static const char* kNullTokenizer = "Error: Unable to construct tokenizer"; -//static const char* kNullToken = "Error: Null token given"; -//static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; -static const char* kViewSourceCommand= "view-source"; - -static nsAutoString gEmpty; -static CTokenRecycler gTokenRecycler; - /** * This method gets called as part of our COM-like interfaces. @@ -120,8 +110,6 @@ NS_IMPL_ADDREF(CViewSourceHTML) NS_IMPL_RELEASE(CViewSourceHTML) -static CTokenDeallocator gTokenKiller; - void SetFont(const char* aFace,const char* aSize,PRBool aEnable,nsIContentSink& aSink) { if(aEnable){ @@ -176,7 +164,7 @@ void SetStyle(eHTMLTags theTag,PRBool aEnable,nsIContentSink& aSink) { * @param * @return */ -CViewSourceHTML::CViewSourceHTML() : nsIDTD(), mTokenDeque(gTokenKiller) { +CViewSourceHTML::CViewSourceHTML() : nsIDTD() { NS_INIT_REFCNT(); mParser=0; mSink=0; diff --git a/mozilla/parser/htmlparser/src/nsViewSourceHTML.h b/mozilla/parser/htmlparser/src/nsViewSourceHTML.h index 719d7c6f5d9..c85e097f1a4 100644 --- a/mozilla/parser/htmlparser/src/nsViewSourceHTML.h +++ b/mozilla/parser/htmlparser/src/nsViewSourceHTML.h @@ -31,8 +31,6 @@ #include "nsISupports.h" #include "nsHTMLTokens.h" #include "nshtmlpars.h" -#include "nsVoidArray.h" -#include "nsDeque.h" #include "nsIHTMLContentSink.h" #define NS_VIEWSOURCE_HTML_IID \ @@ -243,7 +241,6 @@ protected: nsIHTMLContentSink* mSink; nsString mFilename; PRInt32 mLineNumber; - nsDeque mTokenDeque; PRBool mIsHTML; nsITokenizer* mTokenizer; PRInt32 mHasOpenHead; diff --git a/mozilla/parser/htmlparser/src/nsWellFormedDTD.cpp b/mozilla/parser/htmlparser/src/nsWellFormedDTD.cpp index 33cb9318901..12fd485b7e0 100644 --- a/mozilla/parser/htmlparser/src/nsWellFormedDTD.cpp +++ b/mozilla/parser/htmlparser/src/nsWellFormedDTD.cpp @@ -52,17 +52,6 @@ static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID); static NS_DEFINE_IID(kClassIID, NS_WELLFORMED_DTD_IID); -//static const char* kNullURL = "Error: Null URL given"; -//static const char* kNullFilename= "Error: Null filename given"; -//static const char* kNullTokenizer = "Error: Unable to construct tokenizer"; -//static const char* kNullToken = "Error: Null token given"; -//static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; -static const char* kViewSourceCommand= "view-source"; - -static nsAutoString gEmpty; -static CTokenRecycler gTokenRecycler; - - /** * This method gets called as part of our COM-like interfaces. * Its purpose is to create an interface to parser object @@ -120,7 +109,7 @@ NS_IMPL_ADDREF(CWellFormedDTD) NS_IMPL_RELEASE(CWellFormedDTD) -static CTokenDeallocator gTokenKiller; +//static CTokenDeallocator gTokenKiller; /** * Default constructor @@ -129,7 +118,7 @@ static CTokenDeallocator gTokenKiller; * @param * @return */ -CWellFormedDTD::CWellFormedDTD() : nsIDTD(), mTokenDeque(gTokenKiller) { +CWellFormedDTD::CWellFormedDTD() : nsIDTD() { NS_INIT_REFCNT(); mParser=0; mSink=0; diff --git a/mozilla/parser/htmlparser/src/nsWellFormedDTD.h b/mozilla/parser/htmlparser/src/nsWellFormedDTD.h index a2560b9560f..af42d2f0f6d 100644 --- a/mozilla/parser/htmlparser/src/nsWellFormedDTD.h +++ b/mozilla/parser/htmlparser/src/nsWellFormedDTD.h @@ -31,8 +31,6 @@ #include "nsISupports.h" #include "nsHTMLTokens.h" #include "nshtmlpars.h" -#include "nsVoidArray.h" -#include "nsDeque.h" #include "nsIContentSink.h" #define NS_WELLFORMED_DTD_IID \ @@ -235,7 +233,6 @@ protected: nsIContentSink* mSink; nsString mFilename; PRInt32 mLineNumber; - nsDeque mTokenDeque; nsITokenizer* mTokenizer; }; diff --git a/mozilla/parser/htmlparser/src/nsXIFDTD.cpp b/mozilla/parser/htmlparser/src/nsXIFDTD.cpp index 7c8bec83f07..dace83a142a 100644 --- a/mozilla/parser/htmlparser/src/nsXIFDTD.cpp +++ b/mozilla/parser/htmlparser/src/nsXIFDTD.cpp @@ -43,8 +43,6 @@ static NS_DEFINE_IID(kClassIID, NS_XIF_DTD_IID); static const char* kNullToken = "Error: Null token given"; static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; static const char* kXIFDocHeader= ""; - -static nsAutoString gEmpty; struct nsXIFTagEntry { @@ -309,7 +307,6 @@ public: }; -static nsXIfTokenDeallocator gTokenKiller; /** * Default constructor @@ -318,7 +315,7 @@ static nsXIfTokenDeallocator gTokenKiller; * @param * @return */ -nsXIFDTD::nsXIFDTD() : nsIDTD(), mTokenDeque(gTokenKiller) { +nsXIFDTD::nsXIFDTD() : nsIDTD(){ NS_INIT_REFCNT(); mParser=0; mTokenizer=0; diff --git a/mozilla/parser/htmlparser/src/nsXIFDTD.h b/mozilla/parser/htmlparser/src/nsXIFDTD.h index 49d342f244d..7bdb8b04426 100644 --- a/mozilla/parser/htmlparser/src/nsXIFDTD.h +++ b/mozilla/parser/htmlparser/src/nsXIFDTD.h @@ -34,7 +34,6 @@ #include "nsIDTD.h" #include "nsIContentSink.h" #include "nsHTMLTokens.h" -#include "nsDeque.h" #include "nsVoidArray.h" #include @@ -533,7 +532,6 @@ protected: PRBool mHasOpenForm; PRBool mHasOpenMap; - nsDeque mTokenDeque; nsIDTDDebug* mDTDDebug; diff --git a/mozilla/parser/htmlparser/src/nsXMLTokenizer.cpp b/mozilla/parser/htmlparser/src/nsXMLTokenizer.cpp index de1f6dfb311..c72058ebabc 100644 --- a/mozilla/parser/htmlparser/src/nsXMLTokenizer.cpp +++ b/mozilla/parser/htmlparser/src/nsXMLTokenizer.cpp @@ -37,7 +37,6 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kITokenizerIID, NS_ITOKENIZER_IID); static NS_DEFINE_IID(kHTMLTokenizerIID, NS_HTMLTOKENIZER_IID); static NS_DEFINE_IID(kClassIID, NS_XMLTOKENIZER_IID); -static nsAutoString gEmpty; /** * This method gets called as part of our COM-like interfaces. @@ -199,12 +198,14 @@ nsresult nsXMLTokenizer::ConsumeComment(PRUnichar aChar,nsScanner& aScanner,CTok result = ConsumeConditional(aScanner, CDATAString, isCDATA); CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler(); + if (NS_OK == result) { + nsAutoString theEmpty; if (isCDATA) { - aToken=theRecycler->CreateTokenOfType(eToken_cdatasection,eHTMLTag_unknown,gEmpty); + aToken=theRecycler->CreateTokenOfType(eToken_cdatasection,eHTMLTag_unknown,theEmpty); } else { - aToken=theRecycler->CreateTokenOfType(eToken_comment,eHTMLTag_comment,gEmpty); + aToken=theRecycler->CreateTokenOfType(eToken_comment,eHTMLTag_comment,theEmpty); } } diff --git a/mozilla/xpcom/ds/nsDeque.cpp b/mozilla/xpcom/ds/nsDeque.cpp index ac5ead5752d..94443a2c5cd 100644 --- a/mozilla/xpcom/ds/nsDeque.cpp +++ b/mozilla/xpcom/ds/nsDeque.cpp @@ -28,8 +28,8 @@ * @update gess4/18/98 * @return new deque */ -nsDeque::nsDeque(nsDequeFunctor& aMemDestroyer) : mMemDestroyer(aMemDestroyer) { - mMemDestroyer=aMemDestroyer; +nsDeque::nsDeque(nsDequeFunctor* aDeallocator) { + mDeallocator=aDeallocator; mCapacity=eGrowthDelta; mOrigin=mSize=0; mData=new void*[mCapacity]; @@ -44,6 +44,10 @@ nsDeque::~nsDeque() { Erase(); delete [] mData; mData=0; + if(mDeallocator) { + delete mDeallocator; + } + mDeallocator=0; } @@ -82,7 +86,9 @@ nsDeque& nsDeque::Empty() { * @return this */ nsDeque& nsDeque::Erase() { - ForEach(mMemDestroyer); + if(mDeallocator) { + ForEach(*mDeallocator); + } return Empty(); } diff --git a/mozilla/xpcom/ds/nsDeque.h b/mozilla/xpcom/ds/nsDeque.h index 01add17a223..7c8314786dd 100644 --- a/mozilla/xpcom/ds/nsDeque.h +++ b/mozilla/xpcom/ds/nsDeque.h @@ -71,7 +71,7 @@ public: class NS_BASE nsDeque { friend class nsDequeIterator; public: - nsDeque(nsDequeFunctor& aMemDestroyer); + nsDeque(nsDequeFunctor* aDeallocator); ~nsDeque(); /** @@ -215,7 +215,7 @@ protected: PRInt32 mSize; PRInt32 mCapacity; PRInt32 mOrigin; - nsDequeFunctor& mMemDestroyer; + nsDequeFunctor* mDeallocator; void** mData;