diff options
author | kleines Filmröllchen <malu.bertsch@gmail.com> | 2021-11-28 17:24:53 +0100 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-11-28 13:33:51 -0800 |
commit | 295eec2d49b0c361a99915cbcabf33a0a296df32 (patch) | |
tree | 830278c73104be3482a16b8d31a480626396aee0 /AK/Vector.h | |
parent | 05cb499d58bfc2b64fe00c3362d71beb5f3c9494 (diff) | |
download | serenity-295eec2d49b0c361a99915cbcabf33a0a296df32.zip |
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.
Diffstat (limited to 'AK/Vector.h')
-rw-r--r-- | AK/Vector.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/AK/Vector.h b/AK/Vector.h index 751952b987..327be79be8 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -491,7 +491,7 @@ public: ErrorOr<void> try_extend(Vector&& other) { - if (is_empty()) { + if (is_empty() && capacity() <= other.capacity()) { *this = move(other); return {}; } |