Skip to content

Conversation

@abhishek-kaushik22
Copy link
Contributor

Use const& in range-based for loop to avoid unnecessary copies

Use const& in range-based for loop to avoid unnecessary copies
@abhishek-kaushik22 abhishek-kaushik22 requested review from mingmingl-llvm and snehasish and removed request for mingmingl-llvm October 22, 2025 09:11
@llvmbot llvmbot added the PGO Profile Guided Optimizations label Oct 22, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 22, 2025

@llvm/pr-subscribers-pgo

Author: Abhishek Kaushik (abhishek-kaushik22)

Changes

Use const& in range-based for loop to avoid unnecessary copies


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

1 Files Affected:

  • (modified) llvm/include/llvm/ProfileData/SampleProf.h (+1-1)
diff --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h
index 3dd34aba2d716..05f1b568b0643 100644
--- a/llvm/include/llvm/ProfileData/SampleProf.h
+++ b/llvm/include/llvm/ProfileData/SampleProf.h
@@ -1072,7 +1072,7 @@ class FunctionSamples {
     TypeCountMap &TypeCounts = getTypeSamplesAt(Loc);
     bool Overflowed = false;
 
-    for (const auto [Type, Count] : Other) {
+    for (const auto &[Type, Count] : Other) {
       FunctionId TypeId(Type);
       bool RowOverflow = false;
       TypeCounts[TypeId] = SaturatingMultiplyAdd(

Copy link

@snehasish snehasish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@abhishek-kaushik22 abhishek-kaushik22 merged commit a9cc7fe into llvm:main Nov 27, 2025
12 checks passed
@abhishek-kaushik22 abhishek-kaushik22 deleted the fdo_nfc branch November 27, 2025 06:52
augusto2112 pushed a commit to augusto2112/llvm-project that referenced this pull request Dec 3, 2025
Use const& in range-based for loop to avoid unnecessary copies
kcloudy0717 pushed a commit to kcloudy0717/llvm-project that referenced this pull request Dec 4, 2025
Use const& in range-based for loop to avoid unnecessary copies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PGO Profile Guided Optimizations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants