mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-21 10:05:32 +00:00
AK: Stop Vector::extend from unnecessary reallocation
Previously, Vector::extend for a moved vector would move the other vector into this vector if this vector was empty, thereby throwing away existing allocated capacity. Therefore, this commit allows the move to only happen if this vector's capacity is too small to fit the other vector. This will also alleviate bugs where callers relied on the capacity to never shrink with calls to unchecked_append, extend and the like.
This commit is contained in:
parent
05cb499d58
commit
295eec2d49
|
@ -491,7 +491,7 @@ public:
|
|||
|
||||
ErrorOr<void> try_extend(Vector&& other)
|
||||
{
|
||||
if (is_empty()) {
|
||||
if (is_empty() && capacity() <= other.capacity()) {
|
||||
*this = move(other);
|
||||
return {};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue