Resize underlying vector only pos_offset == vector.size()

This commit is contained in:
auxten 2023-06-04 17:44:29 +08:00 committed by GitHub
parent 07a6e49941
commit db806bd394
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();
/// 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());
vector.resize(old_size * size_multiplier);
if (pos_offset == vector.size())
{
vector.resize(old_size * size_multiplier);
}
internal_buffer = Buffer(reinterpret_cast<Position>(vector.data() + pos_offset), reinterpret_cast<Position>(vector.data() + vector.size()));
working_buffer = internal_buffer;
}