Merge pull request #50546 from auxten/patch-1

Resize BufferFromVector underlying vector only pos_offset == vector.size()
This commit is contained in:
Alexey Milovidov 2023-06-05 11:12:57 +03:00 committed by GitHub
commit fb4e950f9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -86,7 +86,10 @@ private:
size_t old_size = vector.size(); size_t old_size = vector.size();
/// pos may not be equal to vector.data() + old_size, because WriteBuffer::next() can be used to flush data /// pos may not be equal to vector.data() + old_size, because WriteBuffer::next() can be used to flush data
size_t pos_offset = pos - reinterpret_cast<Position>(vector.data()); size_t pos_offset = pos - reinterpret_cast<Position>(vector.data());
if (pos_offset == old_size)
{
vector.resize(old_size * size_multiplier); vector.resize(old_size * size_multiplier);
}
internal_buffer = Buffer(reinterpret_cast<Position>(vector.data() + pos_offset), reinterpret_cast<Position>(vector.data() + vector.size())); internal_buffer = Buffer(reinterpret_cast<Position>(vector.data() + pos_offset), reinterpret_cast<Position>(vector.data() + vector.size()));
working_buffer = internal_buffer; working_buffer = internal_buffer;
} }