mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-04 04:58:00 +00:00
Bug 757933 - Switch nsRegionAllocator to ThreadLocal and avoid extra library call. r=BenWa
This commit is contained in:
parent
c09b7245f2
commit
2a33ae1f2a
@ -5,6 +5,7 @@
|
|||||||
#include "nsRegion.h"
|
#include "nsRegion.h"
|
||||||
#include "nsISupportsImpl.h"
|
#include "nsISupportsImpl.h"
|
||||||
#include "nsTArray.h"
|
#include "nsTArray.h"
|
||||||
|
#include "mozilla/ThreadLocal.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The SENTINEL values below guaranties that a < or >
|
* The SENTINEL values below guaranties that a < or >
|
||||||
@ -183,47 +184,43 @@ void RgnRectMemoryAllocator::Free (nsRegion::RgnRect* aRect)
|
|||||||
|
|
||||||
|
|
||||||
// Global pool for nsRegion::RgnRect allocation
|
// Global pool for nsRegion::RgnRect allocation
|
||||||
static PRUintn gRectPoolTlsIndex;
|
mozilla::ThreadLocal<RgnRectMemoryAllocator*> gRectPoolTlsIndex;
|
||||||
|
|
||||||
void RgnRectMemoryAllocatorDTOR(void *priv)
|
void RgnRectMemoryAllocatorDTOR(void *priv)
|
||||||
{
|
{
|
||||||
RgnRectMemoryAllocator* allocator = (static_cast<RgnRectMemoryAllocator*>(
|
RgnRectMemoryAllocator* allocator = gRectPoolTlsIndex.get();
|
||||||
PR_GetThreadPrivate(gRectPoolTlsIndex)));
|
|
||||||
delete allocator;
|
delete allocator;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult nsRegion::InitStatic()
|
nsresult nsRegion::InitStatic()
|
||||||
{
|
{
|
||||||
return PR_NewThreadPrivateIndex(&gRectPoolTlsIndex, RgnRectMemoryAllocatorDTOR);
|
return gRectPoolTlsIndex.init() ? NS_OK : NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nsRegion::ShutdownStatic()
|
void nsRegion::ShutdownStatic()
|
||||||
{
|
{
|
||||||
RgnRectMemoryAllocator* allocator = (static_cast<RgnRectMemoryAllocator*>(
|
RgnRectMemoryAllocator* allocator = gRectPoolTlsIndex.get();
|
||||||
PR_GetThreadPrivate(gRectPoolTlsIndex)));
|
|
||||||
if (!allocator)
|
if (!allocator)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
delete allocator;
|
delete allocator;
|
||||||
|
|
||||||
PR_SetThreadPrivate(gRectPoolTlsIndex, nsnull);
|
gRectPoolTlsIndex.set(nsnull);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* nsRegion::RgnRect::operator new (size_t) CPP_THROW_NEW
|
void* nsRegion::RgnRect::operator new (size_t) CPP_THROW_NEW
|
||||||
{
|
{
|
||||||
RgnRectMemoryAllocator* allocator = (static_cast<RgnRectMemoryAllocator*>(
|
RgnRectMemoryAllocator* allocator = gRectPoolTlsIndex.get();
|
||||||
PR_GetThreadPrivate(gRectPoolTlsIndex)));
|
|
||||||
if (!allocator) {
|
if (!allocator) {
|
||||||
allocator = new RgnRectMemoryAllocator(INIT_MEM_CHUNK_ENTRIES);
|
allocator = new RgnRectMemoryAllocator(INIT_MEM_CHUNK_ENTRIES);
|
||||||
PR_SetThreadPrivate(gRectPoolTlsIndex, allocator);
|
gRectPoolTlsIndex.set(allocator);
|
||||||
}
|
}
|
||||||
return allocator->Alloc ();
|
return allocator->Alloc ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void nsRegion::RgnRect::operator delete (void* aRect, size_t)
|
void nsRegion::RgnRect::operator delete (void* aRect, size_t)
|
||||||
{
|
{
|
||||||
RgnRectMemoryAllocator* allocator = (static_cast<RgnRectMemoryAllocator*>(
|
RgnRectMemoryAllocator* allocator = gRectPoolTlsIndex.get();
|
||||||
PR_GetThreadPrivate(gRectPoolTlsIndex)));
|
|
||||||
if (!allocator) {
|
if (!allocator) {
|
||||||
NS_ERROR("Invalid nsRegion::RgnRect delete");
|
NS_ERROR("Invalid nsRegion::RgnRect delete");
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user