Rolled back in http://trac.webkit.org/changeset/87408 with Windows build fixed.
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 May 2011 20:39:30 +0000 (20:39 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 May 2011 20:39:30 +0000 (20:39 +0000)
* heap/MarkedBlock.cpp:
(JSC::MarkedBlock::MarkedBlock):
* heap/MarkedBlock.h:
* wtf/DoublyLinkedList.h:
(WTF::::DoublyLinkedListNode):
(WTF::::setPrev):
(WTF::::setNext):
(WTF::::prev):
(WTF::::next):
(WTF::::DoublyLinkedList):
(WTF::::isEmpty):
(WTF::::size):
(WTF::::clear):
(WTF::::head):
(WTF::::append):
(WTF::::remove):
(WTF::::removeHead):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@87427 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/heap/MarkedBlock.cpp
Source/JavaScriptCore/heap/MarkedBlock.h
Source/JavaScriptCore/wtf/DoublyLinkedList.h

index a3e609c..23ce84b 100644 (file)
@@ -1,5 +1,27 @@
 2011-05-26  Geoffrey Garen  <ggaren@apple.com>
 
+        Rolled back in http://trac.webkit.org/changeset/87408 with Windows build fixed.
+
+        * heap/MarkedBlock.cpp:
+        (JSC::MarkedBlock::MarkedBlock):
+        * heap/MarkedBlock.h:
+        * wtf/DoublyLinkedList.h:
+        (WTF::::DoublyLinkedListNode):
+        (WTF::::setPrev):
+        (WTF::::setNext):
+        (WTF::::prev):
+        (WTF::::next):
+        (WTF::::DoublyLinkedList):
+        (WTF::::isEmpty):
+        (WTF::::size):
+        (WTF::::clear):
+        (WTF::::head):
+        (WTF::::append):
+        (WTF::::remove):
+        (WTF::::removeHead):
+
+2011-05-26  Geoffrey Garen  <ggaren@apple.com>
+
         Rolled out http://trac.webkit.org/changeset/87408 because it broke the
         Windows build.
 
index aa93b05..94757bc 100644 (file)
@@ -52,8 +52,6 @@ MarkedBlock::MarkedBlock(const PageAllocationAligned& allocation, JSGlobalData*
     : m_nextAtom(firstAtom())
     , m_allocation(allocation)
     , m_heap(&globalData->heap)
-    , m_prev(0)
-    , m_next(0)
 {
     m_atomsPerCell = (cellSize + atomSize - 1) / atomSize;
     m_endAtom = atomsPerBlock - m_atomsPerCell + 1;
index 1ff5f29..35500ab 100644 (file)
@@ -23,6 +23,7 @@
 #define MarkedBlock_h
 
 #include <wtf/Bitmap.h>
+#include <wtf/DoublyLinkedList.h>
 #include <wtf/PageAllocationAligned.h>
 #include <wtf/StdLibExtras.h>
 
@@ -36,7 +37,8 @@ namespace JSC {
 
     static const size_t KB = 1024;
 
-    class MarkedBlock {
+    class MarkedBlock : public DoublyLinkedListNode<MarkedBlock> {
+        friend class WTF::DoublyLinkedListNode<MarkedBlock>;
     public:
         static const size_t atomSize = sizeof(double); // Ensures natural alignment for all built-in types.
 
@@ -49,11 +51,6 @@ namespace JSC {
         
         Heap* heap() const;
 
-        void setPrev(MarkedBlock*);
-        void setNext(MarkedBlock*);
-        MarkedBlock* prev() const;
-        MarkedBlock* next() const;
-        
         void* allocate();
         void reset();
         void sweep();
@@ -124,26 +121,6 @@ namespace JSC {
         return m_heap;
     }
 
-    inline void MarkedBlock::setPrev(MarkedBlock* prev)
-    {
-        m_prev = prev;
-    }
-
-    inline void MarkedBlock::setNext(MarkedBlock* next)
-    {
-        m_next = next;
-    }
-
-    inline MarkedBlock* MarkedBlock::prev() const
-    {
-        return m_prev;
-    }
-
-    inline MarkedBlock* MarkedBlock::next() const
-    {
-        return m_next;
-    }
-
     inline void MarkedBlock::reset()
     {
         m_nextAtom = firstAtom();
index 9351263..18aa00e 100644 (file)
 
 namespace WTF {
 
-template <typename Node> class DoublyLinkedList {
+// This class allows nodes to share code without dictating data member layout.
+template<typename T> class DoublyLinkedListNode {
+public:
+    DoublyLinkedListNode();
+    
+    void setPrev(T*);
+    void setNext(T*);
+    
+    T* prev() const;
+    T* next() const;
+};
+
+template<typename T> inline DoublyLinkedListNode<T>::DoublyLinkedListNode()
+{
+    setPrev(0);
+    setNext(0);
+}
+
+template<typename T> inline void DoublyLinkedListNode<T>::setPrev(T* prev)
+{
+    static_cast<T*>(this)->m_prev = prev;
+}
+
+template<typename T> inline void DoublyLinkedListNode<T>::setNext(T* next)
+{
+    static_cast<T*>(this)->m_next = next;
+}
+
+template<typename T> inline T* DoublyLinkedListNode<T>::prev() const
+{
+    return static_cast<const T*>(this)->m_prev;
+}
+
+template<typename T> inline T* DoublyLinkedListNode<T>::next() const
+{
+    return static_cast<const T*>(this)->m_next;
+}
+
+template<typename T> class DoublyLinkedList {
 public:
     DoublyLinkedList();
     
-    bool isEmpty();
+    bool isEmpty() const;
+    size_t size() const; // This is O(n).
+    void clear();
 
-    Node* head();
+    T* head() const;
+    T* removeHead();
 
-    void append(Node*);
-    void remove(Node*);
+    void append(T*);
+    void remove(T*);
 
 private:
-    Node* m_head;
-    Node* m_tail;
+    T* m_head;
+    T* m_tail;
 };
 
-template <typename Node> inline DoublyLinkedList<Node>::DoublyLinkedList()
+template<typename T> inline DoublyLinkedList<T>::DoublyLinkedList()
     : m_head(0)
     , m_tail(0)
 {
 }
 
-template <typename Node> inline bool DoublyLinkedList<Node>::isEmpty()
+template<typename T> inline bool DoublyLinkedList<T>::isEmpty() const
 {
     return !m_head;
 }
 
-template <typename Node> inline Node* DoublyLinkedList<Node>::head()
+template<typename T> inline size_t DoublyLinkedList<T>::size() const
+{
+    size_t size = 0;
+    for (T* node = m_head; node; node = node->next())
+        ++size;
+    return size;
+}
+
+template<typename T> inline void DoublyLinkedList<T>::clear()
+{
+    m_head = 0;
+    m_tail = 0;
+}
+
+template<typename T> inline T* DoublyLinkedList<T>::head() const
 {
     return m_head;
 }
 
-template <typename Node> inline void DoublyLinkedList<Node>::append(Node* node)
+template<typename T> inline void DoublyLinkedList<T>::append(T* node)
 {
     if (!m_tail) {
         ASSERT(!m_head);
@@ -78,7 +133,7 @@ template <typename Node> inline void DoublyLinkedList<Node>::append(Node* node)
     m_tail = node;
 }
 
-template <typename Node> inline void DoublyLinkedList<Node>::remove(Node* node)
+template<typename T> inline void DoublyLinkedList<T>::remove(T* node)
 {
     if (node->prev()) {
         ASSERT(node != m_head);
@@ -97,8 +152,17 @@ template <typename Node> inline void DoublyLinkedList<Node>::remove(Node* node)
     }
 }
 
+template<typename T> inline T* DoublyLinkedList<T>::removeHead()
+{
+    T* node = head();
+    if (node)
+        remove(node);
+    return node;
+}
+
 } // namespace WTF
 
+using WTF::DoublyLinkedListNode;
 using WTF::DoublyLinkedList;
 
 #endif