]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - parser/ParserArena.cpp
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / parser / ParserArena.cpp
index 261750668efd779f14797ab6c3cabec5c4b24ef5..a276887708c409644db81bcced8ae71b5c04e9a8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2009, 2010 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include "ParserArena.h"
 
 #include "Nodes.h"
+#include "JSCInlines.h"
 
 namespace JSC {
 
-ParserArena::~ParserArena()
+ParserArena::ParserArena()
+    : m_freeableMemory(0)
+    , m_freeablePoolEnd(0)
 {
-    deleteAllValues(m_deletableObjects);
 }
 
-bool ParserArena::contains(ParserArenaRefCounted* object) const
+inline void* ParserArena::freeablePool()
 {
-    return m_refCountedObjects.find(object) != notFound;
+    ASSERT(m_freeablePoolEnd);
+    return m_freeablePoolEnd - freeablePoolSize;
 }
 
-ParserArenaRefCounted* ParserArena::last() const
+inline void ParserArena::deallocateObjects()
 {
-    return m_refCountedObjects.last().get();
+    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]);
 }
 
-void ParserArena::removeLast()
+ParserArena::~ParserArena()
 {
-    m_refCountedObjects.removeLast();
+    deallocateObjects();
 }
 
-void ParserArena::reset()
+void ParserArena::allocateFreeablePool()
 {
-    deleteAllValues(m_deletableObjects);
-    m_deletableObjects.shrink(0);
-    m_refCountedObjects.shrink(0);
+    if (m_freeablePoolEnd)
+        m_freeablePools.append(freeablePool());
+
+    char* pool = static_cast<char*>(fastMalloc(freeablePoolSize));
+    m_freeableMemory = pool;
+    m_freeablePoolEnd = pool + freeablePoolSize;
+    ASSERT(freeablePool() == pool);
 }
 
 }