OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserv ed. | 2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserv ed. |
3 * Copyright (C) 2008 David Levin <levin@chromium.org> | 3 * Copyright (C) 2008 David Levin <levin@chromium.org> |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 } | 273 } |
274 dataLogF("%d rehashes\n", numRehashes); | 274 dataLogF("%d rehashes\n", numRehashes); |
275 dataLogF("%d reinserts\n", numReinserts); | 275 dataLogF("%d reinserts\n", numReinserts); |
276 } | 276 } |
277 }; | 277 }; |
278 #endif | 278 #endif |
279 | 279 |
280 HashTable(); | 280 HashTable(); |
281 ~HashTable() | 281 ~HashTable() |
282 { | 282 { |
283 if (LIKELY(!m_table)) | 283 if (!Allocator::isGarbageCollected) { |
tkent
2014/03/05 01:12:40
nit: We prefer early return.
{
if (Allocator:
| |
284 return; | 284 if (LIKELY(!m_table)) |
285 deallocateTable(m_table, m_tableSize); | 285 return; |
286 m_table = 0; | 286 deallocateTable(m_table, m_tableSize); |
287 m_table = 0; | |
288 } | |
287 } | 289 } |
288 | 290 |
289 HashTable(const HashTable&); | 291 HashTable(const HashTable&); |
290 void swap(HashTable&); | 292 void swap(HashTable&); |
291 HashTable& operator=(const HashTable&); | 293 HashTable& operator=(const HashTable&); |
292 | 294 |
293 // When the hash table is empty, just return the same iterator for end a s for begin. | 295 // When the hash table is empty, just return the same iterator for end a s for begin. |
294 // This is more efficient because we don't have to skip all the empty an d deleted | 296 // This is more efficient because we don't have to skip all the empty an d deleted |
295 // buckets, and iterating an empty table is a common case that's worth o ptimizing. | 297 // buckets, and iterating an empty table is a common case that's worth o ptimizing. |
296 iterator begin() { return isEmpty() ? end() : makeIterator(m_table); } | 298 iterator begin() { return isEmpty() ? end() : makeIterator(m_table); } |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
880 result = Allocator::template backingMalloc<ValueType*, HashTableBack ing>(allocSize); | 882 result = Allocator::template backingMalloc<ValueType*, HashTableBack ing>(allocSize); |
881 for (unsigned i = 0; i < size; i++) | 883 for (unsigned i = 0; i < size; i++) |
882 initializeBucket(result[i]); | 884 initializeBucket(result[i]); |
883 } | 885 } |
884 return result; | 886 return result; |
885 } | 887 } |
886 | 888 |
887 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator> | 889 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator> |
888 void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allo cator>::deallocateTable(ValueType* table, unsigned size) | 890 void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allo cator>::deallocateTable(ValueType* table, unsigned size) |
889 { | 891 { |
890 if (Traits::needsDestruction) { | 892 if (!Allocator::isGarbageCollected) { |
891 for (unsigned i = 0; i < size; ++i) { | 893 if (Traits::needsDestruction) { |
892 if (!isDeletedBucket(table[i])) | 894 for (unsigned i = 0; i < size; ++i) { |
893 table[i].~ValueType(); | 895 if (!isDeletedBucket(table[i])) |
896 table[i].~ValueType(); | |
897 } | |
894 } | 898 } |
899 Allocator::backingFree(table); | |
895 } | 900 } |
896 Allocator::backingFree(table); | |
897 } | 901 } |
898 | 902 |
899 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator> | 903 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator> |
900 void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allo cator>::expand() | 904 void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allo cator>::expand() |
901 { | 905 { |
902 unsigned newSize; | 906 unsigned newSize; |
903 if (!m_tableSize) { | 907 if (!m_tableSize) { |
904 newSize = KeyTraits::minimumTableSize; | 908 newSize = KeyTraits::minimumTableSize; |
905 } else if (mustRehashInPlace()) { | 909 } else if (mustRehashInPlace()) { |
906 newSize = m_tableSize; | 910 newSize = m_tableSize; |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1164 inline bool operator!=(const HashTableIteratorAdapter<T, U>& a, const HashTa bleConstIteratorAdapter<T, U>& b) | 1168 inline bool operator!=(const HashTableIteratorAdapter<T, U>& a, const HashTa bleConstIteratorAdapter<T, U>& b) |
1165 { | 1169 { |
1166 return a.m_impl != b.m_impl; | 1170 return a.m_impl != b.m_impl; |
1167 } | 1171 } |
1168 | 1172 |
1169 } // namespace WTF | 1173 } // namespace WTF |
1170 | 1174 |
1171 #include "wtf/HashIterators.h" | 1175 #include "wtf/HashIterators.h" |
1172 | 1176 |
1173 #endif // WTF_HashTable_h | 1177 #endif // WTF_HashTable_h |
OLD | NEW |