Changeset 19365 in webkit for trunk/JavaScriptCore/wtf
- Timestamp:
- Feb 2, 2007, 9:57:28 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/ListHashSet.h
r19354 r19365 23 23 #define WTF_ListHashSet_h 24 24 25 #include "HashTable.h"26 25 #include "HashSet.h" 26 #include "OwnPtr.h" 27 27 28 28 namespace WTF { … … 76 76 ~ListHashSet(); 77 77 78 void swap(ListHashSet&); 79 78 80 int size() const; 79 81 int capacity() const; … … 109 111 Node* m_head; 110 112 Node* m_tail; 111 NodeAllocator* m_allocator; 112 }; 113 113 OwnPtr<NodeAllocator> m_allocator; 114 }; 114 115 115 116 template<typename ValueArg> struct ListHashSetNodeAllocator { … … 120 121 : m_freeList(pool()) 121 122 { 122 memset(m_pool.pool, 0, sizeof(m_pool ));123 } 124 125 Node* allocate() 123 memset(m_pool.pool, 0, sizeof(m_pool.pool)); 124 } 125 126 Node* allocate() 126 127 { 127 128 Node* result = m_freeList; … … 148 149 fastFree(node); 149 150 } 150 151 151 152 152 private: 153 153 Node* pool() { return reinterpret_cast<Node*>(m_pool.pool); } 154 bool inPool(Node* node) 155 { 156 return reinterpret_cast<char*>(node) >= m_pool.pool && reinterpret_cast<char*>(node) < m_pool.pool + sizeof(m_pool.pool); 154 155 bool inPool(Node* node) 156 { 157 return node >= pool() && node < pool() + m_poolSize; 157 158 } 158 159 … … 186 187 }; 187 188 188 template<typename ValueArg, typename HashArg> class ListHashSetIterator 189 { 189 template<typename ValueArg, typename HashArg> class ListHashSetIterator { 190 190 private: 191 191 typedef ListHashSet<ValueArg, HashArg> ListHashSetType; … … 230 230 }; 231 231 232 template<typename ValueArg, typename HashArg> class ListHashSetConstIterator 233 { 232 template<typename ValueArg, typename HashArg> class ListHashSetConstIterator { 234 233 private: 235 234 typedef ListHashSet<ValueArg, HashArg> ListHashSetType; … … 255 254 } 256 255 257 // default copy, assignment and destructor are OK if CHECK_HASHTABLE_ITERATORS is 0258 259 256 PointerType get() const 260 257 { … … 326 323 : m_head(0) 327 324 , m_tail(0) 325 , m_allocator(new NodeAllocator) 328 326 { 329 327 const_iterator end = other.end(); … … 336 334 { 337 335 ListHashSet tmp(other); 338 m_impl.swap(tmp.m_impl);336 swap(tmp); 339 337 return *this; 340 338 } 341 339 342 340 template<typename T, typename U> 341 inline void ListHashSet<T, U>::swap(ListHashSet& other) 342 { 343 m_impl.swap(other.m_impl); 344 std::swap(m_head, other.m_head); 345 std::swap(m_tail, other.m_tail); 346 m_allocator.swap(other.m_allocator); 347 return *this; 348 } 349 350 template<typename T, typename U> 343 351 inline ListHashSet<T, U>::~ListHashSet() 344 352 { 345 353 deleteAllNodes(); 346 delete m_allocator;347 354 } 348 355 … … 396 403 if (it == m_impl.end()) 397 404 return end(); 398 399 405 return makeIterator(*it); 400 406 } … … 407 413 if (it == m_impl.end()) 408 414 return end(); 409 return makeConstIterator(* (m_impl.template find<ValueType, Translator>(value)));415 return makeConstIterator(*it); 410 416 } 411 417 … … 421 427 { 422 428 typedef ListHashSetTranslator<ValueType, HashFunctions> Translator; 423 pair<typename ImplType::iterator, bool> result = m_impl.template add<ValueType, NodeAllocator*, Translator>(value, m_allocator);429 pair<typename ImplType::iterator, bool> result = m_impl.template add<ValueType, NodeAllocator*, Translator>(value, m_allocator.get()); 424 430 if (result.second) 425 appendNode(*(result.first)); 426 427 return std::make_pair(makeIterator(*(result.first)), result.second); 431 appendNode(*result.first); 432 return std::make_pair(makeIterator(*result.first), result.second); 428 433 } 429 434 … … 433 438 if (it == end()) 434 439 return; 435 436 440 m_impl.remove(it.node()); 437 441 unlinkAndDelete(it.node()); … … 472 476 } 473 477 474 node->destroy(m_allocator );478 node->destroy(m_allocator.get()); 475 479 } 476 480 … … 499 503 500 504 for (Node* node = m_head, *next = m_head->m_next; node; node = next, next = node ? node->m_next : 0) 501 node->destroy(m_allocator );505 node->destroy(m_allocator.get()); 502 506 } 503 507
Note:
See TracChangeset
for help on using the changeset viewer.