mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +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
Notes:
sideshowbarker
2024-07-18 00:33:52 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/295eec2d49b Pull-request: https://github.com/SerenityOS/serenity/pull/10331 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/Hendiadyoin1 Reviewed-by: https://github.com/alimpfard
1 changed files with 1 additions and 1 deletions
|
@ -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