[llvm] [ADT] Only call reserve on empty containers in append_values (PR #172109)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 13 03:15:41 PST 2025
================
@@ -2152,7 +2152,17 @@ void append_range(Container &C, Range &&R) {
/// Appends all `Values` to container `C`.
template <typename Container, typename... Args>
void append_values(Container &C, Args &&...Values) {
- C.reserve(range_size(C) + sizeof...(Args));
+ if (size_t InitialSize = range_size(C); InitialSize == 0) {
----------------
nikic wrote:
Side note: This code should be using `llvm::size()` and not `range_size()`. It makes notsense to do a full container scan with `std::distance()` in this context.
If we have any usages where `size()` is not available, those should just not attempt to reserve() at all.
https://github.com/llvm/llvm-project/pull/172109
More information about the llvm-commits
mailing list