/** * This method inserts the given node onto the front of this stack * * @update gess 11/10/99 */ void nsEntryStack::PushFront(nsCParserNode* aNode, nsEntryStack* aStyleStack, bool aRefCntNode) { if(aNode) { if(mCount<mCapacity) { PRInt32 index=0; for(index=mCount;index>0;index--) { mEntries[index]=mEntries[index-1]; } } else { EnsureCapacityFor(mCount+1,1); } mEntries[0].mTag = (eHTMLTags)aNode->GetNodeType(); if (aRefCntNode) { aNode->mUseCount++; mEntries[0].mNode = const_cast<nsCParserNode*>(aNode); IF_HOLD(mEntries[0].mNode); } mEntries[0].mParent=aStyleStack; mEntries[0].mStyles=0; ++mCount; } }
void nsEntryStack::PushEntry(nsTagEntry* aEntry, bool aRefCntNode) { if (aEntry) { EnsureCapacityFor(mCount+1); mEntries[mCount].mNode = aEntry->mNode; mEntries[mCount].mTag = aEntry->mTag; mEntries[mCount].mParent = aEntry->mParent; mEntries[mCount].mStyles = aEntry->mStyles; if (aRefCntNode && mEntries[mCount].mNode) { mEntries[mCount].mNode->mUseCount++; IF_HOLD(mEntries[mCount].mNode); } mCount++; } }
/** * * @update gess 04/22/99 */ void nsEntryStack::Push(nsCParserNode* aNode, nsEntryStack* aStyleStack, bool aRefCntNode) { if(aNode) { EnsureCapacityFor(mCount+1); mEntries[mCount].mTag = (eHTMLTags)aNode->GetNodeType(); if (aRefCntNode) { aNode->mUseCount++; mEntries[mCount].mNode = const_cast<nsCParserNode*>(aNode); IF_HOLD(mEntries[mCount].mNode); } mEntries[mCount].mParent=aStyleStack; mEntries[mCount++].mStyles=0; } }
nsresult nsCParserNode::Init(CToken* aToken, nsTokenAllocator* aTokenAllocator, nsNodeAllocator* aNodeAllocator) { mTokenAllocator = aTokenAllocator; mToken = aToken; if (mTokenAllocator) { IF_HOLD(mToken); } // Else a stack-based token mGenericState = false; mUseCount=0; #ifdef HEAP_ALLOCATED_NODES mNodeAllocator = aNodeAllocator; #endif return NS_OK; }
/** * Constructor * * @update gess 3/25/98 * @param aToken -- token to init internal token * @return */ nsCParserNode::nsCParserNode(CToken* aToken, nsTokenAllocator* aTokenAllocator, nsNodeAllocator* aNodeAllocator) : mRefCnt(0), mGenericState(false), mUseCount(0), mToken(aToken), mTokenAllocator(aTokenAllocator) { MOZ_COUNT_CTOR(nsCParserNode); static int theNodeCount = 0; ++theNodeCount; if (mTokenAllocator) { IF_HOLD(mToken); } // Else a stack-based token #ifdef HEAP_ALLOCATED_NODES mNodeAllocator = aNodeAllocator; #endif }
nsNodeAllocator::nsNodeAllocator():mSharedNodes(0){ #ifdef DEBUG_TRACK_NODES mCount=0; #endif #else static const size_t kNodeBuckets[] = { sizeof(nsCParserNode), sizeof(nsCParserStartNode) }; static const PRInt32 kNumNodeBuckets = sizeof(kNodeBuckets) / sizeof(size_t); static const PRInt32 kInitialNodePoolSize = NS_SIZE_IN_HEAP(sizeof(nsCParserNode)) * 35; // optimal size based on space-trace data nsNodeAllocator::nsNodeAllocator() { mNodePool.Init("NodePool", kNodeBuckets, kNumNodeBuckets, kInitialNodePoolSize); #endif MOZ_COUNT_CTOR(nsNodeAllocator); } nsNodeAllocator::~nsNodeAllocator() { MOZ_COUNT_DTOR(nsNodeAllocator); #ifdef HEAP_ALLOCATED_NODES nsCParserNode* theNode = 0; while((theNode=(nsCParserNode*)mSharedNodes.Pop())){ #ifdef DEBUG_TRACK_NODES RemoveNode(theNode); #endif ::operator delete(theNode); theNode=nsnull; } #ifdef DEBUG_TRACK_NODES if(mCount) { printf("**************************\n"); printf("%i out of %i nodes leaked!\n",gAllNodeCount,mCount); printf("**************************\n"); } #endif #endif } nsCParserNode* nsNodeAllocator::CreateNode(CToken* aToken, nsTokenAllocator* aTokenAllocator) { nsCParserNode* result = 0; #ifdef HEAP_ALLOCATED_NODES #if 0 if(gAllNodeCount!=mSharedNodes.GetSize()) { int x=10; //this is very BAD! } #endif result = static_cast<nsCParserNode*>(mSharedNodes.Pop()); if (result) { result->Init(aToken, aTokenAllocator,this); } else{ result = nsCParserNode::Create(aToken, aTokenAllocator,this); #ifdef DEBUG_TRACK_NODES ++mCount; AddNode(static_cast<nsCParserNode*>(result)); #endif IF_HOLD(result); } #else eHTMLTokenTypes type = aToken ? eHTMLTokenTypes(aToken->GetTokenType()) : eToken_unknown; switch (type) { case eToken_start: result = nsCParserStartNode::Create(aToken, aTokenAllocator,this); break; default : result = nsCParserNode::Create(aToken, aTokenAllocator,this); break; } IF_HOLD(result); #endif return result; }