#include "config.h"
#include "ParserArena.h"
#include "Nodes.h"
#include <wtf/PassOwnPtr.h>
namespace JSC {
ParserArena::ParserArena()
: m_freeableMemory(0)
, m_freeablePoolEnd(0)
{
}
inline void* ParserArena::freeablePool()
{
ASSERT(m_freeablePoolEnd);
return m_freeablePoolEnd - freeablePoolSize;
}
inline void ParserArena::deallocateObjects()
{
size_t size = m_deletableObjects.size();
for (size_t i = 0; i < size; ++i)
m_deletableObjects[i]->~ParserArenaDeletable();
if (m_freeablePoolEnd)
fastFree(freeablePool());
size = m_freeablePools.size();
for (size_t i = 0; i < size; ++i)
fastFree(m_freeablePools[i]);
}
ParserArena::~ParserArena()
{
deallocateObjects();
}
bool ParserArena::contains(ParserArenaRefCounted* object) const
{
return m_refCountedObjects.find(object) != notFound;
}
ParserArenaRefCounted* ParserArena::last() const
{
return m_refCountedObjects.last().get();
}
void ParserArena::removeLast()
{
m_refCountedObjects.removeLast();
}
void ParserArena::reset()
{
deallocateObjects();
m_freeableMemory = 0;
m_freeablePoolEnd = 0;
if (m_identifierArena)
m_identifierArena->clear();
m_freeablePools.clear();
m_deletableObjects.clear();
m_refCountedObjects.clear();
}
void ParserArena::allocateFreeablePool()
{
if (m_freeablePoolEnd)
m_freeablePools.append(freeablePool());
char* pool = static_cast<char*>(fastMalloc(freeablePoolSize));
m_freeableMemory = pool;
m_freeablePoolEnd = pool + freeablePoolSize;
ASSERT(freeablePool() == pool);
}
bool ParserArena::isEmpty() const
{
return !m_freeablePoolEnd
&& (!m_identifierArena || m_identifierArena->isEmpty())
&& m_freeablePools.isEmpty()
&& m_deletableObjects.isEmpty()
&& m_refCountedObjects.isEmpty();
}
void ParserArena::derefWithArena(PassRefPtr<ParserArenaRefCounted> object)
{
m_refCountedObjects.append(object);
}
}