mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 02:33:06 +01:00
66bedcb549
This fixes the final (I think?) reference invalidation in `SmallVector` that we need to fix to align with `std::vector`. (There is still some left in the range insert / append / assign, but the standard calls that UB for `std::vector` so I think we don't care?) For POD-like types, reimplement `emplace_back()` in terms of `push_back()`, taking a copy even for large `T` rather than lose the realloc optimization in `grow_pod()`. For other types, split the grow operation in three and construct the new element in the middle. - `mallocForGrow()` calculates the new capacity and returns the result of `safe_malloc()`. We only need a single definition per `SmallVectorBase` so this is defined in SmallVector.cpp to avoid code size bloat. Moving this part of non-POD grow to the source file also allows the logic to be easily shared with `grow_pod`, and `report_size_overflow()` and `report_at_maximum_capacity()` can move there too. - `moveElementsForGrow()` moves elements from the old to the new allocation. - `takeAllocationForGrow()` frees the old allocation and saves the new allocation and capacity . `SmallVector:assign(size_type, const T&)` also uses the split-grow operations for non-POD, but it also has a semantic change when not growing. Previously, assign would start with `clear()`, and so the old elements were destructed and all elements of the new vector were copy-constructed (potentially invalidating references). The new implementation skips destruction and uses copy-assignment for the prefix of the new vector that fits. The new semantics match what libc++ does for `std::vector::assign()`. Note that the following is another possible implementation: ``` void assign(size_type NumElts, ValueParamT Elt) { std::fill_n(this->begin(), std::min(NumElts, this->size()), Elt); this->resize(NumElts, Elt); } ``` The downside of this simpler implementation is that if the vector has to grow there will be `size()` redundant copy operations. (I had planned on splitting this patch up into three for committing (after getting performance numbers / initial review), but I've realized that if this does for some reason need to be reverted we'll probably want to revert the whole package...) Differential Revision: https://reviews.llvm.org/D94739 |
||
---|---|---|
.. | ||
AnyTest.cpp | ||
APFixedPointTest.cpp | ||
APFloatTest.cpp | ||
APIntTest.cpp | ||
APSIntTest.cpp | ||
ArrayRefTest.cpp | ||
BitFieldsTest.cpp | ||
BitmaskEnumTest.cpp | ||
BitVectorTest.cpp | ||
BreadthFirstIteratorTest.cpp | ||
BumpPtrListTest.cpp | ||
CMakeLists.txt | ||
CoalescingBitVectorTest.cpp | ||
DAGDeltaAlgorithmTest.cpp | ||
DeltaAlgorithmTest.cpp | ||
DenseMapTest.cpp | ||
DenseSetTest.cpp | ||
DepthFirstIteratorTest.cpp | ||
DirectedGraphTest.cpp | ||
EnumeratedArrayTest.cpp | ||
EquivalenceClassesTest.cpp | ||
FallibleIteratorTest.cpp | ||
FloatingPointMode.cpp | ||
FoldingSet.cpp | ||
FunctionExtrasTest.cpp | ||
FunctionRefTest.cpp | ||
HashingTest.cpp | ||
IListBaseTest.cpp | ||
IListIteratorTest.cpp | ||
IListNodeBaseTest.cpp | ||
IListNodeTest.cpp | ||
IListSentinelTest.cpp | ||
IListTest.cpp | ||
ImmutableListTest.cpp | ||
ImmutableMapTest.cpp | ||
ImmutableSetTest.cpp | ||
IntEqClassesTest.cpp | ||
IntervalMapTest.cpp | ||
IntrusiveRefCntPtrTest.cpp | ||
IteratorTest.cpp | ||
MappedIteratorTest.cpp | ||
MapVectorTest.cpp | ||
OptionalTest.cpp | ||
PackedVectorTest.cpp | ||
PointerEmbeddedIntTest.cpp | ||
PointerIntPairTest.cpp | ||
PointerSumTypeTest.cpp | ||
PointerUnionTest.cpp | ||
PostOrderIteratorTest.cpp | ||
PriorityWorklistTest.cpp | ||
RangeAdapterTest.cpp | ||
SCCIteratorTest.cpp | ||
ScopeExitTest.cpp | ||
SequenceTest.cpp | ||
SetVectorTest.cpp | ||
SimpleIListTest.cpp | ||
SmallPtrSetTest.cpp | ||
SmallSetTest.cpp | ||
SmallStringTest.cpp | ||
SmallVectorTest.cpp | ||
SparseBitVectorTest.cpp | ||
SparseMultiSetTest.cpp | ||
SparseSetTest.cpp | ||
StatisticTest.cpp | ||
STLExtrasTest.cpp | ||
StringExtrasTest.cpp | ||
StringMapTest.cpp | ||
StringRefTest.cpp | ||
StringSetTest.cpp | ||
StringSwitchTest.cpp | ||
TestGraph.h | ||
TinyPtrVectorTest.cpp | ||
TripleTest.cpp | ||
TwineTest.cpp | ||
TypeSwitchTest.cpp | ||
TypeTraitsTest.cpp | ||
WaymarkingTest.cpp |