llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-static-analyzer-1

Author: Balázs Benics (steakhal)

<details>
<summary>Changes</summary>

`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

---
Full diff: https://github.com/llvm/llvm-project/pull/246889.diff


1 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Core/RegionStore.cpp (-2) 


``````````diff
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);
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/246889
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to