[llvm] [NFC][SampleFDO] Use const& to avoid copies (PR #164584)

Abhishek Kaushik via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 22 02:11:51 PDT 2025


https://github.com/abhishek-kaushik22 created https://github.com/llvm/llvm-project/pull/164584

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

>From c2c6470f48d49a85fb99a75394ce5f9809814446 Mon Sep 17 00:00:00 2001
From: Abhishek Kaushik <abhishek.kaushik at intel.com>
Date: Wed, 22 Oct 2025 14:40:57 +0530
Subject: [PATCH] [NFC][SampleFDO] Use const& to avoid copies

Use const& in range-based for loop to avoid unnecessary copies
---
 llvm/include/llvm/ProfileData/SampleProf.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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(



More information about the llvm-commits mailing list