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

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: finalize HashTable 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
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> {
Mikhail 2014/03/11 09:58:13 imho this inheritance looks a bit over-complicated
zerny-chromium 2014/03/11 10:04:48 The issue with doing so is that then HashTable wil
Mikhail 2014/03/11 12:02:53 Ah I see, thanks for the explanation.
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);

Powered by Google App Engine
This is Rietveld 408576698