Bug 847248 (part 9) - Remove nsFixedSizeAllocator from parser/htmlparser/. r=hsivonen.

--HG--
extra : rebase_source : 9a9bbdeb87a2d7a3739777ad152937c09caa82d1
This commit is contained in:
Nicholas Nethercote 2013-03-05 16:51:40 -08:00
parent 08daa3b287
commit 1c40305ba0
5 changed files with 30 additions and 81 deletions

View File

@ -73,8 +73,6 @@ protected:
* @update gess 3/25/98
*/
class CStartToken: public CHTMLToken {
CTOKEN_IMPL_SIZEOF
public:
CStartToken(eHTMLTags aTag=eHTMLTag_unknown);
CStartToken(const nsAString& aString);
@ -120,8 +118,6 @@ protected:
* @update gess 3/25/98
*/
class CEndToken: public CHTMLToken {
CTOKEN_IMPL_SIZEOF
public:
CEndToken(eHTMLTags aTag);
CEndToken(const nsAString& aString);
@ -148,8 +144,6 @@ protected:
* @update gess 3/25/98
*/
class CCommentToken: public CHTMLToken {
CTOKEN_IMPL_SIZEOF
public:
CCommentToken();
CCommentToken(const nsAString& aString);
@ -175,8 +169,6 @@ protected:
* @update gess 3/25/98
*/
class CEntityToken : public CHTMLToken {
CTOKEN_IMPL_SIZEOF
public:
CEntityToken();
CEntityToken(const nsAString& aString);
@ -204,8 +196,6 @@ protected:
* @update gess 3/25/98
*/
class CWhitespaceToken: public CHTMLToken {
CTOKEN_IMPL_SIZEOF
public:
CWhitespaceToken();
CWhitespaceToken(const nsAString& aString);
@ -225,8 +215,6 @@ protected:
* @update gess 3/25/98
*/
class CTextToken: public CHTMLToken {
CTOKEN_IMPL_SIZEOF
public:
CTextToken();
CTextToken(const nsAString& aString);
@ -265,8 +253,6 @@ protected:
* @update vidur 11/12/98
*/
class CCDATASectionToken : public CHTMLToken {
CTOKEN_IMPL_SIZEOF
public:
CCDATASectionToken(eHTMLTags aTag = eHTMLTag_unknown);
CCDATASectionToken(const nsAString& aString);
@ -286,8 +272,6 @@ protected:
*
*/
class CMarkupDeclToken : public CHTMLToken {
CTOKEN_IMPL_SIZEOF
public:
CMarkupDeclToken();
CMarkupDeclToken(const nsAString& aString);
@ -309,8 +293,6 @@ protected:
* @update gess 3/25/98
*/
class CAttributeToken: public CHTMLToken {
CTOKEN_IMPL_SIZEOF
public:
CAttributeToken();
CAttributeToken(const nsAString& aString);
@ -341,8 +323,6 @@ protected:
* @update gess 3/25/98
*/
class CNewlineToken: public CHTMLToken {
CTOKEN_IMPL_SIZEOF
public:
CNewlineToken();
virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner,int32_t aMode);
@ -362,8 +342,6 @@ public:
* @update gess 3/25/98
*/
class CInstructionToken: public CHTMLToken {
CTOKEN_IMPL_SIZEOF
public:
CInstructionToken();
CInstructionToken(const nsAString& aString);
@ -383,8 +361,6 @@ protected:
*/
class CDoctypeDeclToken: public CHTMLToken {
CTOKEN_IMPL_SIZEOF
public:
CDoctypeDeclToken(eHTMLTags aTag=eHTMLTag_unknown);
CDoctypeDeclToken(const nsAString& aString,eHTMLTags aTag=eHTMLTag_unknown);

View File

@ -16,20 +16,11 @@
* of that particular token type gets detected in the
* input stream.
*
* CToken objects that are allocated from the heap _must_ be allocated
* using the nsTokenAllocator: the nsTokenAllocator object uses an
* arena to manage the tokens.
*
* The nsTokenAllocator object's arena implementation requires
* object size at destruction time to properly recycle the object;
* therefore, CToken::operator delete() is not public. Instead,
* heap-allocated tokens should be destroyed using the static
* Destroy() method, which accepts a token and the arena from which
* the token was allocated.
*
* Leaf classes (that are actually instantiated from the heap) must
* implement the SizeOf() method, which Destroy() uses to determine
* the size of the token in order to properly recycle it.
* CToken objects that are allocated from the heap are allocated
* using the nsTokenAllocator object. nsTokenAllocator used to use
* an arena-style allocator, but that is no longer necessary or helpful;
* it now uses a trivial drop-in replacement for the arena-style
* allocator called nsDummyAllocator, which just wraps malloc/free.
*/
@ -39,26 +30,25 @@
#include "prtypes.h"
#include "nsString.h"
#include "nsError.h"
#include "nsFixedSizeAllocator.h"
class nsScanner;
class nsTokenAllocator;
/**
* A trivial allocator. See the comment at the top of this file.
*/
class nsDummyAllocator {
public:
void* Alloc(size_t aSize) { return malloc(aSize); }
void Free(void* aPtr) { free(aPtr); }
};
enum eContainerInfo {
eWellFormed,
eMalformed,
eFormUnknown
};
/**
* Implement the SizeOf() method; leaf classes derived from CToken
* must declare this.
*/
#define CTOKEN_IMPL_SIZEOF \
protected: \
virtual size_t SizeOf() const { return sizeof(*this); } \
public:
/**
* Token objects represent sequences of characters as they
* are consumed from the input stream (URL). While they're
@ -85,7 +75,7 @@ class CToken {
* @param aSize -
* @param aArena - Allocate memory from this pool.
*/
static void * operator new (size_t aSize,nsFixedSizeAllocator& anArena) CPP_THROW_NEW
static void * operator new (size_t aSize, nsDummyAllocator& anArena) CPP_THROW_NEW
{
return anArena.Alloc(aSize);
}
@ -106,11 +96,10 @@ class CToken {
/**
* Destroy a token.
*/
static void Destroy(CToken* aToken,nsFixedSizeAllocator& aArenaPool)
static void Destroy(CToken* aToken, nsDummyAllocator& aArenaPool)
{
size_t sz = aToken->SizeOf();
aToken->~CToken();
aArenaPool.Free(aToken, sz);
aArenaPool.Free(aToken);
}
public:
@ -127,7 +116,7 @@ class CToken {
* Free yourself if no one is holding you.
* @update harishd 08/02/00
*/
void Release(nsFixedSizeAllocator& aArenaPool) {
void Release(nsDummyAllocator& aArenaPool) {
--mUseCount;
NS_LOG_RELEASE(this, mUseCount, "CToken");
if (mUseCount==0)
@ -259,11 +248,6 @@ class CToken {
protected:
/**
* Returns the size of the token object.
*/
virtual size_t SizeOf() const = 0;
int32_t mTypeID;
int32_t mUseCount;
int32_t mNewlineCount;

View File

@ -759,10 +759,6 @@ void nsDTDContext::ReleaseGlobalObjects(void){
Now define the nsTokenAllocator class...
**************************************************************/
static const size_t kTokenBuckets[] ={sizeof(CStartToken),sizeof(CAttributeToken),sizeof(CCommentToken),sizeof(CEndToken)};
static const int32_t kNumTokenBuckets = sizeof(kTokenBuckets) / sizeof(size_t);
static const int32_t kInitialTokenPoolSize = sizeof(CToken) * 200;
/**
*
* @update gess7/25/98
@ -772,8 +768,6 @@ nsTokenAllocator::nsTokenAllocator() {
MOZ_COUNT_CTOR(nsTokenAllocator);
mArenaPool.Init("TokenPool", kTokenBuckets, kNumTokenBuckets, kInitialTokenPoolSize);
#ifdef DEBUG
int i=0;
for(i=0;i<eToken_last-1;++i) {
@ -920,15 +914,11 @@ nsNodeAllocator::nsNodeAllocator():mSharedNodes(0){
mCount=0;
#endif
#else
static const size_t kNodeBuckets[] = { sizeof(nsCParserNode), sizeof(nsCParserStartNode) };
static const int32_t kNumNodeBuckets = sizeof(kNodeBuckets) / sizeof(size_t);
static const int32_t kInitialNodePoolSize = 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);

View File

@ -25,7 +25,6 @@
#include "nsITokenizer.h"
#include "nsString.h"
#include "nsIParserNode.h"
#include "nsFixedSizeAllocator.h"
#include "nsCOMArray.h"
#include "nsIParserService.h"
#include "nsReadableUtils.h"
@ -222,10 +221,10 @@ public:
CToken* CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag, const nsAString& aString);
CToken* CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag);
nsFixedSizeAllocator& GetArenaPool() { return mArenaPool; }
nsDummyAllocator& GetArenaPool() { return mArenaPool; }
protected:
nsFixedSizeAllocator mArenaPool;
nsDummyAllocator mArenaPool;
#ifdef DEBUG
int mTotals[eToken_last-1];
#endif
@ -250,7 +249,7 @@ public:
~nsNodeAllocator();
nsCParserNode* CreateNode(CToken* aToken=nullptr, nsTokenAllocator* aTokenAllocator=0);
nsFixedSizeAllocator& GetArenaPool() { return mNodePool; }
nsDummyAllocator& GetArenaPool() { return mNodePool; }
#ifdef HEAP_ALLOCATED_NODES
void Recycle(nsCParserNode* aNode) { mSharedNodes.Push(static_cast<void*>(aNode)); }
@ -262,7 +261,7 @@ protected:
#endif
protected:
nsFixedSizeAllocator mNodePool;
nsDummyAllocator mNodePool;
};
/************************************************************************
@ -325,10 +324,10 @@ public:
**************************************************************/
class CTokenDeallocator: public nsDequeFunctor{
protected:
nsFixedSizeAllocator& mArenaPool;
nsDummyAllocator& mArenaPool;
public:
CTokenDeallocator(nsFixedSizeAllocator& aArenaPool)
CTokenDeallocator(nsDummyAllocator& aArenaPool)
: mArenaPool(aArenaPool) {}
virtual void* operator()(void* anObject) {

View File

@ -45,7 +45,7 @@ class nsCParserNode : public nsIParserNode {
++mRefCnt;
}
void Release(nsFixedSizeAllocator& aPool)
void Release(nsDummyAllocator& aPool)
{
if (--mRefCnt == 0)
Destroy(this, aPool);
@ -74,7 +74,7 @@ class nsCParserNode : public nsIParserNode {
#ifdef HEAP_ALLOCATED_NODES
return new
#else
nsFixedSizeAllocator& pool = aNodeAllocator->GetArenaPool();
nsDummyAllocator& pool = aNodeAllocator->GetArenaPool();
void* place = pool.Alloc(sizeof(nsCParserNode));
NS_ENSURE_TRUE(place, nullptr);
return ::new (place)
@ -82,13 +82,13 @@ class nsCParserNode : public nsIParserNode {
nsCParserNode(aToken, aTokenAllocator, aNodeAllocator);
}
static void Destroy(nsCParserNode* aNode, nsFixedSizeAllocator& aPool)
static void Destroy(nsCParserNode* aNode, nsDummyAllocator& aPool)
{
#ifdef HEAP_ALLOCATED_NODES
delete aNode;
#else
aNode->~nsCParserNode();
aPool.Free(aNode, sizeof(*aNode));
aPool.Free(aNode);
#endif
}
@ -251,7 +251,7 @@ public:
#ifdef HEAP_ALLOCATED_NODES
return new
#else
nsFixedSizeAllocator& pool = aNodeAllocator->GetArenaPool();
nsDummyAllocator& pool = aNodeAllocator->GetArenaPool();
void* place = pool.Alloc(sizeof(nsCParserStartNode));
NS_ENSURE_TRUE(place, nullptr);
return ::new (place)