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

Side by Side Diff: third_party/WebKit/Source/wtf/Vector.h

Issue 2065443002: Rename and improve "traceable" templates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment rewording Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 348
349 T* buffer() { return m_buffer; } 349 T* buffer() { return m_buffer; }
350 const T* buffer() const { return m_buffer; } 350 const T* buffer() const { return m_buffer; }
351 size_t capacity() const { return m_capacity; } 351 size_t capacity() const { return m_capacity; }
352 352
353 void clearUnusedSlots(T* from, T* to) 353 void clearUnusedSlots(T* from, T* to)
354 { 354 {
355 // If the vector backing is garbage-collected and needs tracing or 355 // If the vector backing is garbage-collected and needs tracing or
356 // finalizing, we clear out the unused slots so that the visitor or the 356 // finalizing, we clear out the unused slots so that the visitor or the
357 // finalizer does not cause a problem when visiting the unused slots. 357 // finalizer does not cause a problem when visiting the unused slots.
358 VectorUnusedSlotClearer<Allocator::isGarbageCollected && (VectorTraits<T >::needsDestruction || NeedsTracingTrait<VectorTraits<T>>::value), T>::clear(fro m, to); 358 VectorUnusedSlotClearer<Allocator::isGarbageCollected && (VectorTraits<T >::needsDestruction || IsTraceableInCollectionTrait<VectorTraits<T>>::value), T> ::clear(from, to);
359 } 359 }
360 360
361 void checkUnusedSlots(const T* from, const T* to) 361 void checkUnusedSlots(const T* from, const T* to)
362 { 362 {
363 #if ENABLE(ASSERT) && !defined(ANNOTATE_CONTIGUOUS_CONTAINER) 363 #if ENABLE(ASSERT) && !defined(ANNOTATE_CONTIGUOUS_CONTAINER)
364 VectorUnusedSlotClearer<Allocator::isGarbageCollected && (VectorTraits<T >::needsDestruction || NeedsTracingTrait<VectorTraits<T>>::value), T>::checkClea red(from, to); 364 VectorUnusedSlotClearer<Allocator::isGarbageCollected && (VectorTraits<T >::needsDestruction || IsTraceableInCollectionTrait<VectorTraits<T>>::value), T> ::checkCleared(from, to);
365 #endif 365 #endif
366 } 366 }
367 367
368 // |end| is exclusive, a la STL. 368 // |end| is exclusive, a la STL.
369 struct OffsetRange final { 369 struct OffsetRange final {
370 OffsetRange() : begin(0), end(0) { } 370 OffsetRange() : begin(0), end(0) { }
371 explicit OffsetRange(size_t begin, size_t end) : begin(begin), end(end) { ASSERT(begin <= end); } 371 explicit OffsetRange(size_t begin, size_t end) : begin(begin), end(end) { ASSERT(begin <= end); }
372 bool empty() const { return begin == end; } 372 bool empty() const { return begin == end; }
373 size_t begin; 373 size_t begin;
374 size_t end; 374 size_t end;
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 typedef T value_type; 771 typedef T value_type;
772 772
773 typedef T* iterator; 773 typedef T* iterator;
774 typedef const T* const_iterator; 774 typedef const T* const_iterator;
775 typedef std::reverse_iterator<iterator> reverse_iterator; 775 typedef std::reverse_iterator<iterator> reverse_iterator;
776 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 776 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
777 777
778 Vector() 778 Vector()
779 { 779 {
780 static_assert(!std::is_polymorphic<T>::value || !VectorTraits<T>::canIni tializeWithMemset, "Cannot initialize with memset if there is a vtable"); 780 static_assert(!std::is_polymorphic<T>::value || !VectorTraits<T>::canIni tializeWithMemset, "Cannot initialize with memset if there is a vtable");
781 static_assert(Allocator::isGarbageCollected || !AllowsOnlyPlacementNew<T >::value || !NeedsTracing<T>::value, "Cannot put DISALLOW_NEW_EXCEPT_PLACEMENT_N EW objects that have trace methods into an off-heap Vector"); 781 static_assert(Allocator::isGarbageCollected || !AllowsOnlyPlacementNew<T >::value || !IsTraceable<T>::value, "Cannot put DISALLOW_NEW_EXCEPT_PLACEMENT_NE W objects that have trace methods into an off-heap Vector");
782 static_assert(Allocator::isGarbageCollected || !IsPointerToGarbageCollec tedType<T>::value, "Cannot put raw pointers to garbage-collected classes into an off-heap Vector. Use HeapVector<Member<T>> instead."); 782 static_assert(Allocator::isGarbageCollected || !IsPointerToGarbageCollec tedType<T>::value, "Cannot put raw pointers to garbage-collected classes into an off-heap Vector. Use HeapVector<Member<T>> instead.");
783 783
784 ANNOTATE_NEW_BUFFER(begin(), capacity(), 0); 784 ANNOTATE_NEW_BUFFER(begin(), capacity(), 0);
785 m_size = 0; 785 m_size = 0;
786 } 786 }
787 787
788 explicit Vector(size_t size) 788 explicit Vector(size_t size)
789 : Base(size) 789 : Base(size)
790 { 790 {
791 static_assert(!std::is_polymorphic<T>::value || !VectorTraits<T>::canIni tializeWithMemset, "Cannot initialize with memset if there is a vtable"); 791 static_assert(!std::is_polymorphic<T>::value || !VectorTraits<T>::canIni tializeWithMemset, "Cannot initialize with memset if there is a vtable");
792 static_assert(Allocator::isGarbageCollected || !AllowsOnlyPlacementNew<T >::value || !NeedsTracing<T>::value, "Cannot put DISALLOW_NEW_EXCEPT_PLACEMENT_N EW objects that have trace methods into an off-heap Vector"); 792 static_assert(Allocator::isGarbageCollected || !AllowsOnlyPlacementNew<T >::value || !IsTraceable<T>::value, "Cannot put DISALLOW_NEW_EXCEPT_PLACEMENT_NE W objects that have trace methods into an off-heap Vector");
793 static_assert(Allocator::isGarbageCollected || !IsPointerToGarbageCollec tedType<T>::value, "Cannot put raw pointers to garbage-collected classes into an off-heap Vector. Use HeapVector<Member<T>> instead."); 793 static_assert(Allocator::isGarbageCollected || !IsPointerToGarbageCollec tedType<T>::value, "Cannot put raw pointers to garbage-collected classes into an off-heap Vector. Use HeapVector<Member<T>> instead.");
794 794
795 ANNOTATE_NEW_BUFFER(begin(), capacity(), size); 795 ANNOTATE_NEW_BUFFER(begin(), capacity(), size);
796 m_size = size; 796 m_size = size;
797 TypeOperations::initialize(begin(), end()); 797 TypeOperations::initialize(begin(), end());
798 } 798 }
799 799
800 // Off-GC-heap vectors: Destructor should be called. 800 // Off-GC-heap vectors: Destructor should be called.
801 // On-GC-heap vectors: Destructor should be called for inline buffers (if 801 // On-GC-heap vectors: Destructor should be called for inline buffers (if
802 // any) but destructor shouldn't be called for vector backing since it is 802 // any) but destructor shouldn't be called for vector backing since it is
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 // This is a performance optimization for a case where the buffer has 1516 // This is a performance optimization for a case where the buffer has
1517 // been already traced by somewhere. This can happen if the conservative 1517 // been already traced by somewhere. This can happen if the conservative
1518 // scanning traced an on-stack (false-positive or real) pointer to the 1518 // scanning traced an on-stack (false-positive or real) pointer to the
1519 // HeapVector, and then visitor->trace() traces the HeapVector. 1519 // HeapVector, and then visitor->trace() traces the HeapVector.
1520 if (Allocator::isHeapObjectAlive(buffer())) 1520 if (Allocator::isHeapObjectAlive(buffer()))
1521 return; 1521 return;
1522 Allocator::markNoTracing(visitor, buffer()); 1522 Allocator::markNoTracing(visitor, buffer());
1523 } 1523 }
1524 const T* bufferBegin = buffer(); 1524 const T* bufferBegin = buffer();
1525 const T* bufferEnd = buffer() + size(); 1525 const T* bufferEnd = buffer() + size();
1526 if (NeedsTracingTrait<VectorTraits<T>>::value) { 1526 if (IsTraceableInCollectionTrait<VectorTraits<T>>::value) {
1527 for (const T* bufferEntry = bufferBegin; bufferEntry != bufferEnd; buffe rEntry++) 1527 for (const T* bufferEntry = bufferBegin; bufferEntry != bufferEnd; buffe rEntry++)
1528 Allocator::template trace<VisitorDispatcher, T, VectorTraits<T>>(vis itor, *const_cast<T*>(bufferEntry)); 1528 Allocator::template trace<VisitorDispatcher, T, VectorTraits<T>>(vis itor, *const_cast<T*>(bufferEntry));
1529 checkUnusedSlots(buffer() + size(), buffer() + capacity()); 1529 checkUnusedSlots(buffer() + size(), buffer() + capacity());
1530 } 1530 }
1531 } 1531 }
1532 1532
1533 } // namespace WTF 1533 } // namespace WTF
1534 1534
1535 using WTF::Vector; 1535 using WTF::Vector;
1536 1536
1537 #endif // WTF_Vector_h 1537 #endif // WTF_Vector_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698