Bring in some of the changes from erase-between branch

This commit is contained in:
2024-08-15 16:55:26 -07:00
parent 0740dcad43
commit 9d23b81d6f
3 changed files with 160 additions and 56 deletions

View File

@@ -273,6 +273,16 @@ template <class T> struct Vector {
size_ += slice.size();
}
// Caller must write to the returned slice
std::span<T> unsafePrepareAppend(int appendSize) {
if (size_ + appendSize > capacity) {
grow(std::max<int>(size_ + appendSize, capacity * 2));
}
auto result = std::span<T>(t + size_, appendSize);
size_ += appendSize;
return result;
}
void push_back(const T &t) { append(std::span<const T>(&t, 1)); }
T *begin() { return t; }