diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/platform/PODRedBlackTree.h | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/platform/PODRedBlackTree.h')
-rw-r--r-- | Source/WebCore/platform/PODRedBlackTree.h | 81 |
1 files changed, 13 insertions, 68 deletions
diff --git a/Source/WebCore/platform/PODRedBlackTree.h b/Source/WebCore/platform/PODRedBlackTree.h index 484f43af6..1b15daa1a 100644 --- a/Source/WebCore/platform/PODRedBlackTree.h +++ b/Source/WebCore/platform/PODRedBlackTree.h @@ -72,11 +72,9 @@ #ifndef PODRedBlackTree_h #define PODRedBlackTree_h -#include "PODFreeListArena.h" #include "ValueToString.h" #include <wtf/Assertions.h> #include <wtf/Noncopyable.h> -#include <wtf/RefPtr.h> #ifndef NDEBUG #include <wtf/text/CString.h> #include <wtf/text/StringBuilder.h> @@ -85,12 +83,9 @@ namespace WebCore { -enum UninitializedTreeEnum { - UninitializedTree -}; - template<class T> class PODRedBlackTree { + WTF_MAKE_FAST_ALLOCATED; public: class Node; @@ -102,11 +97,7 @@ public: virtual ~Visitor() { } }; - // Constructs a new red-black tree without allocating an arena. - // isInitialized will return false in this case. initIfNeeded can be used - // to init the structure. This constructor is usefull for creating - // lazy initialized tree. - explicit PODRedBlackTree(UninitializedTreeEnum) + PODRedBlackTree() : m_root(0) , m_needsFullOrderingComparisons(false) #ifndef NDEBUG @@ -115,69 +106,28 @@ public: { } - // Constructs a new red-black tree, allocating temporary objects - // from a newly constructed PODFreeListArena. - PODRedBlackTree() - : m_arena(PODFreeListArena<Node>::create()) - , m_root(0) - , m_needsFullOrderingComparisons(false) -#ifndef NDEBUG - , m_verboseDebugging(false) -#endif + virtual ~PODRedBlackTree() { + clear(); } - // Constructs a new red-black tree, allocating temporary objects - // from the given PODArena. - explicit PODRedBlackTree(PassRefPtr<PODFreeListArena<Node>> arena) - : m_arena(arena) - , m_root(0) - , m_needsFullOrderingComparisons(false) -#ifndef NDEBUG - , m_verboseDebugging(false) -#endif - { - } - - virtual ~PODRedBlackTree() { } - // Clearing will delete the contents of the tree. After this call // isInitialized will return false. void clear() { markFree(m_root); - m_arena = 0; m_root = 0; } - bool isInitialized() const - { - return m_arena; - } - - void initIfNeeded() - { - if (!m_arena) - m_arena = PODFreeListArena<Node>::create(); - } - - void initIfNeeded(PODFreeListArena<Node>* arena) - { - if (!m_arena) - m_arena = arena; - } - void add(const T& data) { - ASSERT(isInitialized()); - Node* node = m_arena->template allocateObject<T>(data); + Node* node = new Node(data); insertNode(node); } // Returns true if the datum was found in the tree. bool remove(const T& data) { - ASSERT(isInitialized()); Node* node = treeSearch(data); if (node) { deleteNode(node); @@ -188,13 +138,11 @@ public: bool contains(const T& data) const { - ASSERT(isInitialized()); return treeSearch(data); } void visitInorder(Visitor* visitor) const { - ASSERT(isInitialized()); if (!m_root) return; visitInorderImpl(m_root, visitor); @@ -202,7 +150,6 @@ public: int size() const { - ASSERT(isInitialized()); Counter counter; visitInorder(&counter); return counter.count(); @@ -216,7 +163,6 @@ public: virtual bool checkInvariants() const { - ASSERT(isInitialized()); int blackCount; return checkInvariantsFromNode(m_root, &blackCount); } @@ -226,8 +172,7 @@ public: // debugging purposes. void dump() const { - if (m_arena) - dumpFromNode(m_root, 0); + dumpFromNode(m_root, 0); } // Turns on or off verbose debugging of the tree, causing many @@ -248,6 +193,7 @@ public: // an internal concept; users of the tree deal only with the data // they store in it. class Node { + WTF_MAKE_FAST_ALLOCATED; WTF_MAKE_NONCOPYABLE(Node); public: // Constructor. Newly-created nodes are colored red. @@ -695,7 +641,7 @@ private: if (y->color() == Black) deleteFixup(x, xParent); - m_arena->freeObject(y); + delete y; } // Visits the subtree rooted at the given node in order. @@ -717,7 +663,7 @@ private: markFree(node->left()); if (node->right()) markFree(node->right()); - m_arena->freeObject(node); + delete node; } //---------------------------------------------------------------------- @@ -730,7 +676,7 @@ private: Counter() : m_count(0) { } - virtual void visit(const T&) override { ++m_count; } + void visit(const T&) override { ++m_count; } int count() const { return m_count; } private: @@ -792,10 +738,10 @@ private: { StringBuilder builder; for (int i = 0; i < indentation; i++) - builder.append(" "); - builder.append("-"); + builder.append(' '); + builder.append('-'); if (node) { - builder.append(" "); + builder.append(' '); builder.append(ValueToString<T>::string(node->data())); builder.append((node->color() == Black) ? " (black)" : " (red)"); } @@ -810,7 +756,6 @@ private: //---------------------------------------------------------------------- // Data members - RefPtr<PODFreeListArena<Node>> m_arena; Node* m_root; bool m_needsFullOrderingComparisons; #ifndef NDEBUG |