Changeset 21175 in webkit for trunk/JavaScriptCore/wtf
- Timestamp:
- Apr 28, 2007, 9:25:33 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/ListHashSet.h
r19365 r21175 1 1 // -*- mode: c++; c-basic-offset: 4 -*- 2 2 /* 3 * Copyright (C) 2005, 2006, 2007 Apple Inc. 3 * Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved. 4 4 * 5 5 * This library is free software; you can redistribute it and/or … … 23 23 #define WTF_ListHashSet_h 24 24 25 #include "Assertions.h" 25 26 #include "HashSet.h" 26 27 #include "OwnPtr.h" … … 28 29 namespace WTF { 29 30 30 // ListHashSet: just like HashSet, this class provides a Set31 // ListHashSet: Just like HashSet, this class provides a Set 31 32 // interface - a collection of unique objects with O(1) insertion, 32 33 // removal and test for containership. However, it also has an … … 120 121 ListHashSetNodeAllocator() 121 122 : m_freeList(pool()) 123 , m_isDoneWithInitialFreeList(false) 122 124 { 123 125 memset(m_pool.pool, 0, sizeof(m_pool.pool)); … … 131 133 return static_cast<Node*>(fastMalloc(sizeof(Node))); 132 134 135 ASSERT(!result->m_isAllocated); 136 133 137 Node* next = result->m_next; 134 if (!next && inPool(result + 1)) 138 ASSERT(!next || !next->m_isAllocated); 139 if (!next && !m_isDoneWithInitialFreeList) { 135 140 next = result + 1; 141 if (next == pastPool()) { 142 m_isDoneWithInitialFreeList = true; 143 next = 0; 144 } else { 145 ASSERT(inPool(next)); 146 ASSERT(!next->m_isAllocated); 147 } 148 } 136 149 m_freeList = next; 137 150 138 151 return result; 139 152 } … … 142 155 { 143 156 if (inPool(node)) { 157 #ifndef NDEBUG 158 node->m_isAllocated = false; 159 #endif 144 160 node->m_next = m_freeList; 145 161 m_freeList = node; … … 152 168 private: 153 169 Node* pool() { return reinterpret_cast<Node*>(m_pool.pool); } 170 Node* pastPool() { return pool() + m_poolSize; } 154 171 155 172 bool inPool(Node* node) 156 173 { 157 return node >= pool() && node < p ool() + m_poolSize;174 return node >= pool() && node < pastPool(); 158 175 } 159 176 160 177 Node* m_freeList; 178 bool m_isDoneWithInitialFreeList; 161 179 static const size_t m_poolSize = 256; 162 180 union { … … 169 187 typedef ListHashSetNodeAllocator<ValueArg> NodeAllocator; 170 188 171 ListHashSetNode(ValueArg value) : m_value(value), m_prev(0), m_next(0) {} 172 173 void* operator new(size_t s, NodeAllocator* allocator) { return allocator->allocate(); } 174 void operator delete(void* p) { } 175 void destroy(NodeAllocator* allocator) { delete this; allocator->deallocate(this); } 176 189 ListHashSetNode(ValueArg value) 190 : m_value(value) 191 , m_prev(0) 192 , m_next(0) 193 #ifndef NDEBUG 194 , m_isAllocated(true) 195 #endif 196 { 197 } 198 199 void* operator new(size_t, NodeAllocator* allocator) 200 { 201 return allocator->allocate(); 202 } 203 void destroy(NodeAllocator* allocator) 204 { 205 this->~ListHashSetNode(); 206 allocator->deallocate(this); 207 } 208 177 209 ValueArg m_value; 178 210 ListHashSetNode* m_prev; 179 211 ListHashSetNode* m_next; 212 213 #ifndef NDEBUG 214 bool m_isAllocated; 215 #endif 180 216 }; 181 217
Note:
See TracChangeset
for help on using the changeset viewer.