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 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 initializeBucket(*deletedEntry); | 848 initializeBucket(*deletedEntry); |
849 entry = deletedEntry; | 849 entry = deletedEntry; |
850 --m_deletedCount; | 850 --m_deletedCount; |
851 } | 851 } |
852 | 852 |
853 HashTranslator::translate(*entry, std::forward<T>(key), std::forward<Extra>(
extra)); | 853 HashTranslator::translate(*entry, std::forward<T>(key), std::forward<Extra>(
extra)); |
854 ASSERT(!isEmptyOrDeletedBucket(*entry)); | 854 ASSERT(!isEmptyOrDeletedBucket(*entry)); |
855 | 855 |
856 ++m_keyCount; | 856 ++m_keyCount; |
857 | 857 |
858 if (shouldExpand()) | 858 if (shouldExpand()) { |
859 entry = expand(entry); | 859 entry = expand(entry); |
| 860 } else if (Traits::weakHandlingFlag == WeakHandlingInCollections && shouldSh
rink()) { |
| 861 // When weak hash tables are processed by the garbage collector, |
| 862 // elements with no other strong references to them will have their |
| 863 // table entries cleared. But no shrinking of the backing store is |
| 864 // allowed at that time, as allocations are prohibited during that |
| 865 // GC phase. |
| 866 // |
| 867 // With that weak processing taking care of removals, explicit |
| 868 // remove()s of elements is rarely done. Which implies that the |
| 869 // weak hash table will never be checked if it can be shrunk. |
| 870 // |
| 871 // To prevent weak hash tables with very low load factors from |
| 872 // developing, we perform it when adding elements instead. |
| 873 entry = rehash(m_tableSize / 2, entry); |
| 874 } |
860 | 875 |
861 return AddResult(this, entry, true); | 876 return AddResult(this, entry, true); |
862 } | 877 } |
863 | 878 |
864 template <typename Key, typename Value, typename Extractor, typename HashFunctio
ns, typename Traits, typename KeyTraits, typename Allocator> | 879 template <typename Key, typename Value, typename Extractor, typename HashFunctio
ns, typename Traits, typename KeyTraits, typename Allocator> |
865 template <typename HashTranslator, typename T, typename Extra> | 880 template <typename HashTranslator, typename T, typename Extra> |
866 typename HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allo
cator>::AddResult HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTra
its, Allocator>::addPassingHashCode(T&& key, Extra&& extra) | 881 typename HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allo
cator>::AddResult HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTra
its, Allocator>::addPassingHashCode(T&& key, Extra&& extra) |
867 { | 882 { |
868 ASSERT(!m_accessForbidden); | 883 ASSERT(!m_accessForbidden); |
869 ASSERT(Allocator::isAllocationAllowed()); | 884 ASSERT(Allocator::isAllocationAllowed()); |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1520 CollectionIterator end(toBeRemoved.end()); | 1535 CollectionIterator end(toBeRemoved.end()); |
1521 for (CollectionIterator it(toBeRemoved.begin()); it != end; ++it) | 1536 for (CollectionIterator it(toBeRemoved.begin()); it != end; ++it) |
1522 collection.remove(*it); | 1537 collection.remove(*it); |
1523 } | 1538 } |
1524 | 1539 |
1525 } // namespace WTF | 1540 } // namespace WTF |
1526 | 1541 |
1527 #include "wtf/HashIterators.h" | 1542 #include "wtf/HashIterators.h" |
1528 | 1543 |
1529 #endif // WTF_HashTable_h | 1544 #endif // WTF_HashTable_h |
OLD | NEW |