@@ -61,7 +61,7 @@ template <class Size_T> class SmallVectorBase {
61
61
62
62
SmallVectorBase () = delete ;
63
63
SmallVectorBase (void *FirstEl, size_t TotalCapacity)
64
- : BeginX(FirstEl), Capacity(TotalCapacity) {}
64
+ : BeginX(FirstEl), Capacity(static_cast <Size_T>( TotalCapacity) ) {}
65
65
66
66
// / This is a helper for \a grow() that's out of line to reduce code
67
67
// / duplication. This function will report a fatal error if it can't grow at
@@ -99,8 +99,18 @@ template <class Size_T> class SmallVectorBase {
99
99
// /
100
100
// / This does not construct or destroy any elements in the vector.
101
101
void set_size (size_t N) {
102
- assert (N <= capacity ());
103
- Size = N;
102
+ assert (N <= capacity ()); // implies no overflow in assignment
103
+ Size = static_cast <Size_T>(N);
104
+ }
105
+
106
+ // / Set the array data pointer to \p Begin and capacity to \p N.
107
+ // /
108
+ // / This does not construct or destroy any elements in the vector.
109
+ // This does not clean up any existing allocation.
110
+ void set_allocation_range (void *Begin, size_t N) {
111
+ assert (N <= SizeTypeMax ());
112
+ BeginX = Begin;
113
+ Capacity = static_cast <Size_T>(N);
104
114
}
105
115
};
106
116
@@ -467,8 +477,7 @@ void SmallVectorTemplateBase<T, TriviallyCopyable>::takeAllocationForGrow(
467
477
if (!this ->isSmall ())
468
478
free (this ->begin ());
469
479
470
- this ->BeginX = NewElts;
471
- this ->Capacity = NewCapacity;
480
+ this ->set_allocation_range (NewElts, NewCapacity);
472
481
}
473
482
474
483
// / SmallVectorTemplateBase<TriviallyCopyable = true> - This is where we put
0 commit comments