This source file includes following definitions.
- fastZeroedMalloc
- fastStrDup
- releaseFastMallocFreeMemory
- fastMallocStatistics
- fastMallocShutdown
- fastMalloc
- fastFree
- fastRealloc
- fastMallocShutdown
- fastMalloc
- fastFree
- fastRealloc
#include "config.h"
#include "wtf/FastMalloc.h"
#include <string.h>
namespace WTF {
void* fastZeroedMalloc(size_t n)
{
void* result = fastMalloc(n);
memset(result, 0, n);
return result;
}
char* fastStrDup(const char* src)
{
size_t len = strlen(src) + 1;
char* dup = static_cast<char*>(fastMalloc(len));
memcpy(dup, src, len);
return dup;
}
void releaseFastMallocFreeMemory() { }
FastMallocStatistics fastMallocStatistics()
{
FastMallocStatistics statistics = { 0, 0, 0 };
return statistics;
}
}
#if USE(SYSTEM_MALLOC)
#include "wtf/Assertions.h"
#include <stdlib.h>
namespace WTF {
void fastMallocShutdown()
{
}
void* fastMalloc(size_t n)
{
void* result = malloc(n);
ASSERT(result);
return result;
}
void fastFree(void* p)
{
free(p);
}
void* fastRealloc(void* p, size_t n)
{
void* result = realloc(p, n);
ASSERT(result);
return result;
}
}
#else
#include "wtf/PartitionAlloc.h"
#include "wtf/SpinLock.h"
namespace WTF {
static PartitionAllocatorGeneric gPartition;
static int gLock = 0;
static bool gInitialized = false;
void fastMallocShutdown()
{
gPartition.shutdown();
}
void* fastMalloc(size_t n)
{
if (UNLIKELY(!gInitialized)) {
spinLockLock(&gLock);
if (!gInitialized) {
gInitialized = true;
gPartition.init();
}
spinLockUnlock(&gLock);
}
return partitionAllocGeneric(gPartition.root(), n);
}
void fastFree(void* p)
{
partitionFreeGeneric(gPartition.root(), p);
}
void* fastRealloc(void* p, size_t n)
{
return partitionReallocGeneric(gPartition.root(), p, n);
}
}
#endif