diff options
Diffstat (limited to 'src/3rdparty/webkit/JavaScriptCore/parser/ParserArena.cpp')
-rw-r--r-- | src/3rdparty/webkit/JavaScriptCore/parser/ParserArena.cpp | 72 |
1 files changed, 59 insertions, 13 deletions
diff --git a/src/3rdparty/webkit/JavaScriptCore/parser/ParserArena.cpp b/src/3rdparty/webkit/JavaScriptCore/parser/ParserArena.cpp index 78c5196..a8e8159 100644 --- a/src/3rdparty/webkit/JavaScriptCore/parser/ParserArena.cpp +++ b/src/3rdparty/webkit/JavaScriptCore/parser/ParserArena.cpp @@ -24,16 +24,45 @@ */ #include "config.h" -#include "Parser.h" #include "ParserArena.h" #include "Nodes.h" namespace JSC { +ParserArena::ParserArena() + : m_freeableMemory(0) + , m_freeablePoolEnd(0) + , m_identifierArena(new IdentifierArena) +{ +} + +inline void* ParserArena::freeablePool() +{ + ASSERT(m_freeablePoolEnd); + return m_freeablePoolEnd - freeablePoolSize; +} + +inline void ParserArena::deallocateObjects() +{ + if (m_freeablePoolEnd) + fastFree(freeablePool()); + + size_t size = m_freeablePools.size(); + for (size_t i = 0; i < size; ++i) + fastFree(m_freeablePools[i]); + + size = m_deletableObjects.size(); + for (size_t i = 0; i < size; ++i) { + ParserArenaDeletable* object = m_deletableObjects[i]; + object->~ParserArenaDeletable(); + fastFree(object); + } +} + ParserArena::~ParserArena() { - deleteAllValues(m_deletableObjects); + deallocateObjects(); } bool ParserArena::contains(ParserArenaRefCounted* object) const @@ -53,26 +82,43 @@ void ParserArena::removeLast() void ParserArena::reset() { - deleteAllValues(m_deletableObjects); - m_deletableObjects.shrink(0); - m_refCountedObjects.shrink(0); + // Since this code path is used only when parsing fails, it's not bothering to reuse + // any of the memory the arena allocated. We could improve that later if we want to + // efficiently reuse the same arena. + + deallocateObjects(); + + m_freeableMemory = 0; + m_freeablePoolEnd = 0; + m_identifierArena->clear(); + m_freeablePools.clear(); + m_deletableObjects.clear(); + m_refCountedObjects.clear(); } -void* ParserArenaDeletable::operator new(size_t size, JSGlobalData* globalData) +void ParserArena::allocateFreeablePool() { - ParserArenaDeletable* deletable = static_cast<ParserArenaDeletable*>(fastMalloc(size)); - globalData->parser->arena().deleteWithArena(deletable); - return deletable; + if (m_freeablePoolEnd) + m_freeablePools.append(freeablePool()); + + char* pool = static_cast<char*>(fastMalloc(freeablePoolSize)); + m_freeableMemory = pool; + m_freeablePoolEnd = pool + freeablePoolSize; + ASSERT(freeablePool() == pool); } -void* ParserArenaDeletable::operator new(size_t size) +bool ParserArena::isEmpty() const { - return fastMalloc(size); + return !m_freeablePoolEnd + && m_identifierArena->isEmpty() + && m_freeablePools.isEmpty() + && m_deletableObjects.isEmpty() + && m_refCountedObjects.isEmpty(); } -void ParserArenaDeletable::operator delete(void* p) +void ParserArena::derefWithArena(PassRefPtr<ParserArenaRefCounted> object) { - fastFree(p); + m_refCountedObjects.append(object); } } |