Chromium Code Reviews| Index: Source/wtf/Vector.h |
| diff --git a/Source/wtf/Vector.h b/Source/wtf/Vector.h |
| index b2881deb9cbbad3655e48ad5e3a717fa35d2e099..c3139b471b1a621cccc31c594af358a014f67bfd 100644 |
| --- a/Source/wtf/Vector.h |
| +++ b/Source/wtf/Vector.h |
| @@ -90,8 +90,6 @@ static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE; |
| struct VectorUnusedSlotClearer<true, T> { |
| static void clear(T* begin, T* end) |
| { |
| - // We clear out unused slots so that the visitor and the finalizer |
| - // do not visit them (or at least it does not matter if they do). |
| memset(begin, 0, sizeof(T) * (end - begin)); |
| } |
| @@ -344,6 +342,10 @@ static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE; |
| void clearUnusedSlots(T* from, T* to) |
| { |
| + // If the vector backing is garbage-collected and needs tracing |
| + // or finalizing, we clear out the unused slots so that the visitor |
| + // or the finalizer does not cause a problem when visiting the |
| + // unused slots. |
| VectorUnusedSlotClearer<Allocator::isGarbageCollected && (VectorTraits<T>::needsDestruction || ShouldBeTraced<VectorTraits<T>>::value), T>::clear(from, to); |
| } |
| @@ -635,12 +637,6 @@ static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE; |
| Vector() |
| { |
| - // Unused slots are initialized to zero so that the visitor and the |
| - // finalizer can visit them safely. canInitializeWithMemset tells us |
| - // that the class does not expect matching constructor and |
| - // destructor calls as long as the memory is zeroed. |
| - static_assert(!Allocator::isGarbageCollected || !VectorTraits<T>::needsDestruction || VectorTraits<T>::canInitializeWithMemset, "class has problems with finalizers called on cleared memory"); |
| - static_assert(!WTF::IsPolymorphic<T>::value || !VectorTraits<T>::canInitializeWithMemset, "cannot initialize with memset if there is a vtable"); |
|
sof
2015/04/24 12:40:06
Doesn't this check help catch incorrect trait spec
haraken
2015/04/24 12:45:37
Doesn't the check in HeapVectorBacking::trace and
sof
2015/04/24 12:50:39
Not quite, they trust canInitializeWithMemset is c
haraken
2015/04/24 13:02:26
Makes sense. So...
- We don't need the first stat
sof
2015/04/24 13:11:07
That makes sense to me, the more helpful static_as
haraken
2015/04/24 13:13:47
Done.
|
| ANNOTATE_NEW_BUFFER(begin(), capacity(), 0); |
| m_size = 0; |
| } |
| @@ -648,11 +644,6 @@ static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE; |
| explicit Vector(size_t size) |
| : Base(size) |
| { |
| - // Unused slots are initialized to zero so that the visitor and the |
| - // finalizer can visit them safely. canInitializeWithMemset tells us |
| - // that the class does not expect matching constructor and |
| - // destructor calls as long as the memory is zeroed. |
| - static_assert(!Allocator::isGarbageCollected || !VectorTraits<T>::needsDestruction || VectorTraits<T>::canInitializeWithMemset, "class has problems with finalizers called on cleared memory"); |
| ANNOTATE_NEW_BUFFER(begin(), capacity(), size); |
| m_size = size; |
| TypeOperations::initialize(begin(), end()); |