Decrement mOpenFormCount only if there's an open form. b=115262, r=heikki, sr=jst.\n Counter related code should be DEBUG only. b=92618, r=heikki, sr=jst

This commit is contained in:
harishd%netscape.com 2002-01-11 19:33:31 +00:00
Родитель 1264a2434d
Коммит 670334d2e7
10 изменённых файлов: 126 добавлений и 76 удалений

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

@ -397,7 +397,10 @@ nsresult CNavDTD::WillBuildModel( const CParserContext& aParserContext,nsIConte
STOP_TIMER();
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::WillBuildModel(), this=%p\n", this));
#ifdef DEBUG
mBodyContext->ResetCounters();
#endif
mDocType=aParserContext.mDocType;
if(aSink && (!mSink)) {
@ -982,6 +985,7 @@ nsresult CNavDTD::DidHandleStartTag(nsIParserNode& aNode,eHTMLTags aChildTag){
}
break;
#ifdef DEBUG
case eHTMLTag_counter:
{
PRInt32 theCount=mBodyContext->GetCount();
@ -1026,6 +1030,7 @@ nsresult CNavDTD::DidHandleStartTag(nsIParserNode& aNode,eHTMLTags aChildTag){
}
}
break;
#endif
default:
break;
@ -2126,21 +2131,24 @@ nsresult CNavDTD::HandleEntityToken(CToken* aToken) {
nsAutoString theStr(aToken->GetStringValue());
PRUnichar theChar=theStr.CharAt(0);
if((kHashsign!=theChar) && (-1==nsHTMLEntities::EntityToUnicode(theStr))){
CToken *theToken=0;
#ifdef DEBUG
//before we just toss this away as a bogus entity, let's check...
CNamedEntity *theEntity=mBodyContext->GetEntity(theStr);
CToken *theToken=0;
if(theEntity) {
theToken=NS_STATIC_CAST(CTextToken*,mTokenAllocator->CreateTokenOfType(eToken_text,eHTMLTag_text,theEntity->mValue));
theToken = NS_STATIC_CAST(CTextToken*,mTokenAllocator->CreateTokenOfType(eToken_text,eHTMLTag_text,theEntity->mValue));
}
else {
#endif
//if you're here we have a bogus entity.
//convert it into a text token.
nsAutoString entityName;
entityName.Assign(NS_LITERAL_STRING("&"));
entityName.Append(theStr); //should append the entity name; fix bug 51161.
theToken = mTokenAllocator->CreateTokenOfType(eToken_text,eHTMLTag_text,entityName);
#ifdef DEBUG
}
#endif
return HandleToken(theToken,mParser); //theToken should get recycled automagically...
}
@ -3225,20 +3233,22 @@ nsresult CNavDTD::OpenForm(const nsIParserNode *aNode){
nsresult CNavDTD::CloseForm(const nsIParserNode *aNode){
// NS_PRECONDITION(mBodyContext->GetCount() > 0, kInvalidTagStackPos);
nsresult result=NS_OK;
if((mFlags & NS_PARSER_FLAG_HAS_OPEN_FORM) && (mOpenFormCount == 1)) {
mFlags &= ~NS_PARSER_FLAG_HAS_OPEN_FORM;
if(mFlags & NS_PARSER_FLAG_HAS_OPEN_FORM) {
if (mOpenFormCount == 1) {
mFlags &= ~NS_PARSER_FLAG_HAS_OPEN_FORM;
STOP_TIMER();
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::CloseForm(), this=%p\n", this));
STOP_TIMER();
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::CloseForm(), this=%p\n", this));
result=(mSink) ? mSink->CloseForm(*aNode) : NS_OK;
result=(mSink) ? mSink->CloseForm(*aNode) : NS_OK;
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::CloseForm(), this=%p\n", this));
START_TIMER();
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::CloseForm(), this=%p\n", this));
START_TIMER();
mFlags &= ~NS_PARSER_FLAG_IS_FORM_CONTAINER;
mFlags &= ~NS_PARSER_FLAG_IS_FORM_CONTAINER;
}
--mOpenFormCount;
}
--mOpenFormCount;
return result;
}

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

@ -355,7 +355,9 @@ nsresult COtherDTD::WillBuildModel( const CParserContext& aParserContext,nsICon
if(result==NS_OK) {
result = aSink->WillBuildModel();
#ifdef DEBUG
mBodyContext->ResetCounters();
#endif
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: COtherDTD::WillBuildModel(), this=%p\n", this));
START_TIMER();
@ -574,6 +576,7 @@ nsresult COtherDTD::DidHandleStartTag(nsIParserNode& aNode,eHTMLTags aChildTag){
}
break;
#ifdef DEBUG
case eHTMLTag_meta:
{
//we should only enable user-defined entities in debug builds...
@ -602,6 +605,7 @@ nsresult COtherDTD::DidHandleStartTag(nsIParserNode& aNode,eHTMLTags aChildTag){
}
}
break;
#endif
default:
break;
@ -840,19 +844,23 @@ nsresult COtherDTD::HandleEntityToken(CToken* aToken) {
if((kHashsign!=theChar) && (-1==nsHTMLEntities::EntityToUnicode(theStr))){
#ifdef DEBUG
//before we just toss this away as a bogus entity, let's check...
CNamedEntity *theEntity=mBodyContext->GetEntity(theStr);
if(theEntity) {
theToken=(CTextToken*)mTokenAllocator->CreateTokenOfType(eToken_text,eHTMLTag_text,theEntity->mValue);
}
else {
#endif
//if you're here we have a bogus entity.
//convert it into a text token.
nsAutoString entityName;
entityName.Assign(NS_LITERAL_STRING("&"));
entityName.Append(theStr); //should append the entity name; fix bug 51161.
theToken=(CTextToken*)mTokenAllocator->CreateTokenOfType(eToken_text,eHTMLTag_text,entityName);
#ifdef DEBUG
}
#endif
result=HandleStartToken(theToken);
}
else {

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

@ -1016,14 +1016,18 @@ public:
PRInt32 theCount=aContext->GetCount();
eHTMLTags theGrandParentTag=aContext->TagAt(theCount-2);
nsCParserNode *theNode=(nsCParserNode*)aNode;
nsCParserNode *theNode = (nsCParserNode*)aNode;
#ifdef DEBUG
nsAutoString theNumber;
aContext->IncrementCounter(theGrandParentTag,*theNode,theNumber);
CTextToken theToken(theNumber);
PRInt32 theLineNumber=0;
nsCParserNode theNewNode(&theToken,theLineNumber,0 /*stack token*/);
result=aSink->AddLeaf(theNewNode);
*theNode = theNewNode;
#endif
result=aSink->AddLeaf(*theNode);
return result;
}

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

@ -404,27 +404,26 @@ nsDTDContext::nsDTDContext() : mStack(), mEntities(0){
mResidualStyleCount=0;
mContextTopIndex=-1;
mTableStates=0;
mCounters=0;
mTokenAllocator=0;
mNodeAllocator=0;
mAllBits=0;
#ifdef NS_DEBUG
#ifdef DEBUG
memset(mXTags,0,sizeof(mXTags));
mCounters = 0;
#endif
}
class CEntityDeallocator: public nsDequeFunctor{
public:
virtual void* operator()(void* anObject) {
CNamedEntity *theEntity=(CNamedEntity*)anObject;
delete theEntity;
return 0;
}
};
#ifdef DEBUG
class CEntityDeallocator: public nsDequeFunctor{
public:
virtual void* operator()(void* anObject) {
CNamedEntity *theEntity=(CNamedEntity*)anObject;
delete theEntity;
return 0;
}
};
#endif
/**
*
@ -440,14 +439,18 @@ nsDTDContext::~nsDTDContext() {
delete theState;
}
#ifdef DEBUG
CEntityDeallocator theDeallocator;
mEntities.ForEach(theDeallocator);
if(mCounters) {
delete [] mCounters;
mCounters = 0;
}
#endif
}
#ifdef DEBUG
CNamedEntity* nsDTDContext::GetEntity(const nsString& aName)const {
PRInt32 theCount=mEntities.GetSize();
@ -489,7 +492,6 @@ CNamedEntity* nsDTDContext::RegisterEntity(const nsString& aName,const nsString
return theEntity;
}
/****************************************************************
The abacus class is useful today for debug purposes, but it
will eventually serve as the implementation for css counters.
@ -902,6 +904,7 @@ PRInt32 nsDTDContext::IncrementCounter(eHTMLTags aTag,nsIParserNode& aNode,nsStr
return result;
}
#endif
/**
*

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

@ -230,7 +230,7 @@ public:
CTableState *mPrevious;
};
#ifdef DEBUG
//used for named entities and counters (XXX debug only)
class CNamedEntity {
public:
@ -257,7 +257,7 @@ public:
nsString mValue;
PRInt32 mOrdinal;
};
#endif
/************************************************************************
nsTokenAllocator class implementation.
This class is used to recycle tokens.
@ -354,13 +354,6 @@ public:
static void ReleaseGlobalObjects(void);
CNamedEntity* RegisterEntity(const nsString& aName,const nsString& aValue);
CNamedEntity* GetEntity(const nsString& aName)const;
void ResetCounters(void);
void AllocateCounters(void);
PRInt32 IncrementCounter(eHTMLTags aTag,nsIParserNode& aNode,nsString& aResult);
void SetTokenAllocator(nsTokenAllocator* aTokenAllocator) { mTokenAllocator=aTokenAllocator; }
void SetNodeAllocator(nsNodeAllocator* aNodeAllocator) { mNodeAllocator=aNodeAllocator; }
@ -385,12 +378,19 @@ public:
nsTokenAllocator *mTokenAllocator;
nsNodeAllocator *mNodeAllocator;
CTableState *mTableStates;
PRInt32 *mCounters;
nsDeque mEntities;
#ifdef NS_DEBUG
enum { eMaxTags = 100 };
eHTMLTags mXTags[eMaxTags];
PRInt32 *mCounters;
void ResetCounters(void);
void AllocateCounters(void);
PRInt32 IncrementCounter(eHTMLTags aTag,nsIParserNode& aNode,nsString& aResult);
CNamedEntity* RegisterEntity(const nsString& aName,const nsString& aValue);
CNamedEntity* GetEntity(const nsString& aName)const;
#endif
};

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

@ -397,7 +397,10 @@ nsresult CNavDTD::WillBuildModel( const CParserContext& aParserContext,nsIConte
STOP_TIMER();
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::WillBuildModel(), this=%p\n", this));
#ifdef DEBUG
mBodyContext->ResetCounters();
#endif
mDocType=aParserContext.mDocType;
if(aSink && (!mSink)) {
@ -982,6 +985,7 @@ nsresult CNavDTD::DidHandleStartTag(nsIParserNode& aNode,eHTMLTags aChildTag){
}
break;
#ifdef DEBUG
case eHTMLTag_counter:
{
PRInt32 theCount=mBodyContext->GetCount();
@ -1026,6 +1030,7 @@ nsresult CNavDTD::DidHandleStartTag(nsIParserNode& aNode,eHTMLTags aChildTag){
}
}
break;
#endif
default:
break;
@ -2126,21 +2131,24 @@ nsresult CNavDTD::HandleEntityToken(CToken* aToken) {
nsAutoString theStr(aToken->GetStringValue());
PRUnichar theChar=theStr.CharAt(0);
if((kHashsign!=theChar) && (-1==nsHTMLEntities::EntityToUnicode(theStr))){
CToken *theToken=0;
#ifdef DEBUG
//before we just toss this away as a bogus entity, let's check...
CNamedEntity *theEntity=mBodyContext->GetEntity(theStr);
CToken *theToken=0;
if(theEntity) {
theToken=NS_STATIC_CAST(CTextToken*,mTokenAllocator->CreateTokenOfType(eToken_text,eHTMLTag_text,theEntity->mValue));
theToken = NS_STATIC_CAST(CTextToken*,mTokenAllocator->CreateTokenOfType(eToken_text,eHTMLTag_text,theEntity->mValue));
}
else {
#endif
//if you're here we have a bogus entity.
//convert it into a text token.
nsAutoString entityName;
entityName.Assign(NS_LITERAL_STRING("&"));
entityName.Append(theStr); //should append the entity name; fix bug 51161.
theToken = mTokenAllocator->CreateTokenOfType(eToken_text,eHTMLTag_text,entityName);
#ifdef DEBUG
}
#endif
return HandleToken(theToken,mParser); //theToken should get recycled automagically...
}
@ -3225,20 +3233,22 @@ nsresult CNavDTD::OpenForm(const nsIParserNode *aNode){
nsresult CNavDTD::CloseForm(const nsIParserNode *aNode){
// NS_PRECONDITION(mBodyContext->GetCount() > 0, kInvalidTagStackPos);
nsresult result=NS_OK;
if((mFlags & NS_PARSER_FLAG_HAS_OPEN_FORM) && (mOpenFormCount == 1)) {
mFlags &= ~NS_PARSER_FLAG_HAS_OPEN_FORM;
if(mFlags & NS_PARSER_FLAG_HAS_OPEN_FORM) {
if (mOpenFormCount == 1) {
mFlags &= ~NS_PARSER_FLAG_HAS_OPEN_FORM;
STOP_TIMER();
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::CloseForm(), this=%p\n", this));
STOP_TIMER();
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::CloseForm(), this=%p\n", this));
result=(mSink) ? mSink->CloseForm(*aNode) : NS_OK;
result=(mSink) ? mSink->CloseForm(*aNode) : NS_OK;
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::CloseForm(), this=%p\n", this));
START_TIMER();
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::CloseForm(), this=%p\n", this));
START_TIMER();
mFlags &= ~NS_PARSER_FLAG_IS_FORM_CONTAINER;
mFlags &= ~NS_PARSER_FLAG_IS_FORM_CONTAINER;
}
--mOpenFormCount;
}
--mOpenFormCount;
return result;
}

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

@ -355,7 +355,9 @@ nsresult COtherDTD::WillBuildModel( const CParserContext& aParserContext,nsICon
if(result==NS_OK) {
result = aSink->WillBuildModel();
#ifdef DEBUG
mBodyContext->ResetCounters();
#endif
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: COtherDTD::WillBuildModel(), this=%p\n", this));
START_TIMER();
@ -574,6 +576,7 @@ nsresult COtherDTD::DidHandleStartTag(nsIParserNode& aNode,eHTMLTags aChildTag){
}
break;
#ifdef DEBUG
case eHTMLTag_meta:
{
//we should only enable user-defined entities in debug builds...
@ -602,6 +605,7 @@ nsresult COtherDTD::DidHandleStartTag(nsIParserNode& aNode,eHTMLTags aChildTag){
}
}
break;
#endif
default:
break;
@ -840,19 +844,23 @@ nsresult COtherDTD::HandleEntityToken(CToken* aToken) {
if((kHashsign!=theChar) && (-1==nsHTMLEntities::EntityToUnicode(theStr))){
#ifdef DEBUG
//before we just toss this away as a bogus entity, let's check...
CNamedEntity *theEntity=mBodyContext->GetEntity(theStr);
if(theEntity) {
theToken=(CTextToken*)mTokenAllocator->CreateTokenOfType(eToken_text,eHTMLTag_text,theEntity->mValue);
}
else {
#endif
//if you're here we have a bogus entity.
//convert it into a text token.
nsAutoString entityName;
entityName.Assign(NS_LITERAL_STRING("&"));
entityName.Append(theStr); //should append the entity name; fix bug 51161.
theToken=(CTextToken*)mTokenAllocator->CreateTokenOfType(eToken_text,eHTMLTag_text,entityName);
#ifdef DEBUG
}
#endif
result=HandleStartToken(theToken);
}
else {

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

@ -1016,14 +1016,18 @@ public:
PRInt32 theCount=aContext->GetCount();
eHTMLTags theGrandParentTag=aContext->TagAt(theCount-2);
nsCParserNode *theNode=(nsCParserNode*)aNode;
nsCParserNode *theNode = (nsCParserNode*)aNode;
#ifdef DEBUG
nsAutoString theNumber;
aContext->IncrementCounter(theGrandParentTag,*theNode,theNumber);
CTextToken theToken(theNumber);
PRInt32 theLineNumber=0;
nsCParserNode theNewNode(&theToken,theLineNumber,0 /*stack token*/);
result=aSink->AddLeaf(theNewNode);
*theNode = theNewNode;
#endif
result=aSink->AddLeaf(*theNode);
return result;
}

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

@ -404,27 +404,26 @@ nsDTDContext::nsDTDContext() : mStack(), mEntities(0){
mResidualStyleCount=0;
mContextTopIndex=-1;
mTableStates=0;
mCounters=0;
mTokenAllocator=0;
mNodeAllocator=0;
mAllBits=0;
#ifdef NS_DEBUG
#ifdef DEBUG
memset(mXTags,0,sizeof(mXTags));
mCounters = 0;
#endif
}
class CEntityDeallocator: public nsDequeFunctor{
public:
virtual void* operator()(void* anObject) {
CNamedEntity *theEntity=(CNamedEntity*)anObject;
delete theEntity;
return 0;
}
};
#ifdef DEBUG
class CEntityDeallocator: public nsDequeFunctor{
public:
virtual void* operator()(void* anObject) {
CNamedEntity *theEntity=(CNamedEntity*)anObject;
delete theEntity;
return 0;
}
};
#endif
/**
*
@ -440,14 +439,18 @@ nsDTDContext::~nsDTDContext() {
delete theState;
}
#ifdef DEBUG
CEntityDeallocator theDeallocator;
mEntities.ForEach(theDeallocator);
if(mCounters) {
delete [] mCounters;
mCounters = 0;
}
#endif
}
#ifdef DEBUG
CNamedEntity* nsDTDContext::GetEntity(const nsString& aName)const {
PRInt32 theCount=mEntities.GetSize();
@ -489,7 +492,6 @@ CNamedEntity* nsDTDContext::RegisterEntity(const nsString& aName,const nsString
return theEntity;
}
/****************************************************************
The abacus class is useful today for debug purposes, but it
will eventually serve as the implementation for css counters.
@ -902,6 +904,7 @@ PRInt32 nsDTDContext::IncrementCounter(eHTMLTags aTag,nsIParserNode& aNode,nsStr
return result;
}
#endif
/**
*

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

@ -230,7 +230,7 @@ public:
CTableState *mPrevious;
};
#ifdef DEBUG
//used for named entities and counters (XXX debug only)
class CNamedEntity {
public:
@ -257,7 +257,7 @@ public:
nsString mValue;
PRInt32 mOrdinal;
};
#endif
/************************************************************************
nsTokenAllocator class implementation.
This class is used to recycle tokens.
@ -354,13 +354,6 @@ public:
static void ReleaseGlobalObjects(void);
CNamedEntity* RegisterEntity(const nsString& aName,const nsString& aValue);
CNamedEntity* GetEntity(const nsString& aName)const;
void ResetCounters(void);
void AllocateCounters(void);
PRInt32 IncrementCounter(eHTMLTags aTag,nsIParserNode& aNode,nsString& aResult);
void SetTokenAllocator(nsTokenAllocator* aTokenAllocator) { mTokenAllocator=aTokenAllocator; }
void SetNodeAllocator(nsNodeAllocator* aNodeAllocator) { mNodeAllocator=aNodeAllocator; }
@ -385,12 +378,19 @@ public:
nsTokenAllocator *mTokenAllocator;
nsNodeAllocator *mNodeAllocator;
CTableState *mTableStates;
PRInt32 *mCounters;
nsDeque mEntities;
#ifdef NS_DEBUG
enum { eMaxTags = 100 };
eHTMLTags mXTags[eMaxTags];
PRInt32 *mCounters;
void ResetCounters(void);
void AllocateCounters(void);
PRInt32 IncrementCounter(eHTMLTags aTag,nsIParserNode& aNode,nsString& aResult);
CNamedEntity* RegisterEntity(const nsString& aName,const nsString& aValue);
CNamedEntity* GetEntity(const nsString& aName)const;
#endif
};