bug 504034: initialize RgnRectMemoryAllocator non-statically by heap allocating it. r=vlad

This commit is contained in:
Chris Jones 2009-09-09 20:22:03 -05:00
parent a7b25c0ea5
commit 9d0f93c04d
4 changed files with 33 additions and 4 deletions

View File

@ -205,6 +205,16 @@ public:
*/
void SimpleSubtract (const nsRegion& aRegion);
/**
* Initialize any static data associated with nsRegion.
*/
static nsresult InitStatic();
/**
* Deinitialize static data.
*/
static void ShutdownStatic();
private:
PRUint32 mRectCount;
RgnRect* mCurRect;

View File

@ -206,17 +206,27 @@ void RgnRectMemoryAllocator::Free (nsRegion::RgnRect* aRect)
// Global pool for nsRegion::RgnRect allocation
static RgnRectMemoryAllocator gRectPool (INIT_MEM_CHUNK_ENTRIES);
static RgnRectMemoryAllocator* gRectPool;
nsresult nsRegion::InitStatic()
{
gRectPool = new RgnRectMemoryAllocator(INIT_MEM_CHUNK_ENTRIES);
return !gRectPool ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
}
void nsRegion::ShutdownStatic()
{
delete gRectPool;
}
void* nsRegion::RgnRect::operator new (size_t) CPP_THROW_NEW
{
return gRectPool.Alloc ();
return gRectPool->Alloc ();
}
void nsRegion::RgnRect::operator delete (void* aRect, size_t)
{
gRectPool.Free (static_cast<RgnRect*>(aRect));
gRectPool->Free (static_cast<RgnRect*>(aRect));
}

View File

@ -245,7 +245,7 @@ gfxPlatform::Shutdown()
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs)
prefs->RemoveObserver(CMForceSRGBPrefName, gPlatform->overrideObserver);
delete gPlatform;
gPlatform = nsnull;
}

View File

@ -65,6 +65,7 @@
#include "nsLayoutStylesheetCache.h"
#include "nsNodeInfo.h"
#include "nsRange.h"
#include "nsRegion.h"
#include "nsRepeatService.h"
#include "nsFloatManager.h"
#include "nsSprocketLayout.h"
@ -155,6 +156,12 @@ nsLayoutStatics::Initialize()
nsGkAtoms::AddRefAtoms();
nsJSRuntime::Startup();
rv = nsRegion::InitStatic();
if (NS_FAILED(rv)) {
NS_ERROR("Could not initialize nsRegion");
return rv;
}
rv = nsContentUtils::Init();
if (NS_FAILED(rv)) {
NS_ERROR("Could not initialize nsContentUtils");
@ -376,6 +383,8 @@ nsLayoutStatics::Shutdown()
nsHtml5Module::ReleaseStatics();
nsRegion::ShutdownStatic();
NS_ShutdownChainItemPool();
nsFrameList::Shutdown();