summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/javascriptcore/JavaScriptCore/parser/ParserArena.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/javascriptcore/JavaScriptCore/parser/ParserArena.cpp')
-rw-r--r--src/3rdparty/javascriptcore/JavaScriptCore/parser/ParserArena.cpp81
1 files changed, 69 insertions, 12 deletions
diff --git a/src/3rdparty/javascriptcore/JavaScriptCore/parser/ParserArena.cpp b/src/3rdparty/javascriptcore/JavaScriptCore/parser/ParserArena.cpp
index 78c5196a92..6a2af8335c 100644
--- a/src/3rdparty/javascriptcore/JavaScriptCore/parser/ParserArena.cpp
+++ b/src/3rdparty/javascriptcore/JavaScriptCore/parser/ParserArena.cpp
@@ -31,9 +31,39 @@
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 +83,53 @@ 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)
+{
+ m_refCountedObjects.append(object);
+}
+
+void* ParserArenaFreeable::operator new(size_t size, JSGlobalData* globalData)
+{
+ return globalData->parser->arena().allocateFreeable(size);
+}
+
+void* ParserArenaDeletable::operator new(size_t size, JSGlobalData* globalData)
{
- fastFree(p);
+ return globalData->parser->arena().allocateDeletable(size);
}
}