[clang] a26d5a8 - [analyzer][NFC] Drop redundant reserve before append_range (#246889)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 29 06:24:14 PST 2026
Author: Balázs Benics
Date: 2026-11-29T14:24:09Z
New Revision: a26d5a8f530d4e1ae0b99306ef4566410591e80d
URL: https://github.com/llvm/llvm-project/commit/a26d5a8f530d4e1ae0b99306ef4566410591e80d
DIFF: https://github.com/llvm/llvm-project/commit/a26d5a8f530d4e1ae0b99306ef4566410591e80d.diff
LOG: [analyzer][NFC] Drop redundant reserve before append_range (#246889)
`llvm::append_range(C, R)` expands to `C.insert(C.end(), begin(R),
end(R))`. For `std::vector`, insert with forward-or-better iterators
computes the distance up front and performs a single allocation of the
exact size, so a preceding `reserve(std::distance(...))` of the same
range is redundant (and only adds an extra `O(n)` traversal for
non-random-access ranges).
The two sites in `RegionStore.cpp` append `map_range()` over an
`ImmutableMap`. `ImmutableMap` iterators are bidirectional and
`mapped_iterator` preserves the underlying iterator category, so the
insert already reserves. No other `append_range` call in the analyzer
has a reserve at the same site.
I didn't measure the perf impact of this, but I'm 100% it doesn't change
anything.
Assisted-by: Claude Code
Added:
Modified:
clang/lib/StaticAnalyzer/Core/RegionStore.cpp
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
index a93f5af26244b..ea8e429551dd9 100644
--- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -293,7 +293,6 @@ class RegionBindingsRef : public llvm::ImmutableMapRef<const MemRegion *,
const auto AddrOf = [](const auto &Item) { return &Item; };
std::vector<const Cluster *> SortedClusters;
- SortedClusters.reserve(std::distance(begin(), end()));
append_range(SortedClusters, map_range(*this, AddrOf));
llvm::sort(SortedClusters, MemSpaceBeforeRegionName);
@@ -304,7 +303,6 @@ class RegionBindingsRef : public llvm::ImmutableMapRef<const MemRegion *,
<< (const void *)BaseRegion << "\", \"items\": [" << NL;
std::vector<const Binding *> SortedBindings;
- SortedBindings.reserve(std::distance(Bindings.begin(), Bindings.end()));
append_range(SortedBindings, map_range(Bindings, AddrOf));
llvm::sort(SortedBindings, DefaultBindingBeforeDirectBindings);
More information about the cfe-commits
mailing list