Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1441)

Unified Diff: Source/wtf/HashTable.h

Issue 189543014: Ensure proper finalization of garbage-collected types. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase and sign error in Vector Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/platform/Supplementable.h ('k') | Source/wtf/Vector.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/HashTable.h
diff --git a/Source/wtf/HashTable.h b/Source/wtf/HashTable.h
index 30c8bbd5ef55f94a0169bbea561c132d835d5fcd..7fa35151df60091b9e2ffa8b3781006e83727c71 100644
--- a/Source/wtf/HashTable.h
+++ b/Source/wtf/HashTable.h
@@ -218,8 +218,21 @@ namespace WTF {
static bool isEmptyOrDeletedBucket(const Value& value) { return isEmptyBucket(value) || isDeletedBucket(value); }
};
+ // Don't declare a destructor for HeapAllocated hash tables.
+ template<typename Derived, bool isGarbageCollected>
+ class HashTableDestructorBase;
+
+ template<typename Derived>
+ class HashTableDestructorBase<Derived, true> { };
+
+ template<typename Derived>
+ class HashTableDestructorBase<Derived, false> {
+ public:
+ ~HashTableDestructorBase() { static_cast<Derived*>(this)->finalize(); }
+ };
+
template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits, typename Allocator>
- class HashTable {
+ class HashTable : public HashTableDestructorBase<HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>, Allocator::isGarbageCollected> {
public:
typedef HashTableIterator<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator> iterator;
typedef HashTableConstIterator<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator> const_iterator;
@@ -278,10 +291,9 @@ namespace WTF {
#endif
HashTable();
- ~HashTable()
+ void finalize()
{
- if (Allocator::isGarbageCollected)
- return;
+ ASSERT(!Allocator::isGarbageCollected);
if (LIKELY(!m_table))
return;
deallocateTable(m_table, m_tableSize);
« no previous file with comments | « Source/platform/Supplementable.h ('k') | Source/wtf/Vector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698