[llvm] [CGData] Return ArrayRef<std::string> in getNames (NFC) (PR #140675)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Mon May 19 21:50:52 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/140675
All uses of getNames is read access to the list of names, so we can
just return ArrayRef<std::string>. There is no need to make a copy as
we prepare a return value.
>From ee40f710187454ec94c8d99ca981a782747c466b Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 19 May 2025 21:44:58 -0700
Subject: [PATCH] [CGData] Return ArrayRef<std::string> in getNames (NFC)
All uses of getNames is read access to the list of names, so we can
just return ArrayRef<std::string>. There is no need to make a copy as
we prepare a return value.
---
llvm/include/llvm/CGData/StableFunctionMap.h | 2 +-
llvm/lib/CGData/StableFunctionMapRecord.cpp | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/CGData/StableFunctionMap.h b/llvm/include/llvm/CGData/StableFunctionMap.h
index 8881adf5889d0..a3a85b92c3b30 100644
--- a/llvm/include/llvm/CGData/StableFunctionMap.h
+++ b/llvm/include/llvm/CGData/StableFunctionMap.h
@@ -78,7 +78,7 @@ struct StableFunctionMap {
const HashFuncsMapType &getFunctionMap() const { return HashToFuncs; }
/// Get the NameToId vector for serialization.
- const SmallVector<std::string> getNames() const { return IdToName; }
+ ArrayRef<std::string> getNames() const { return IdToName; }
/// Get an existing ID associated with the given name or create a new ID if it
/// doesn't exist.
diff --git a/llvm/lib/CGData/StableFunctionMapRecord.cpp b/llvm/lib/CGData/StableFunctionMapRecord.cpp
index e23b0e072c9a3..8cf8ab56c3f91 100644
--- a/llvm/lib/CGData/StableFunctionMapRecord.cpp
+++ b/llvm/lib/CGData/StableFunctionMapRecord.cpp
@@ -86,7 +86,7 @@ void StableFunctionMapRecord::serialize(raw_ostream &OS,
support::endian::Writer Writer(OS, endianness::little);
// Write Names.
- auto &Names = FunctionMap->getNames();
+ auto Names = FunctionMap->getNames();
uint32_t ByteSize = 4;
Writer.write<uint32_t>(Names.size());
for (auto &Name : Names) {
More information about the llvm-commits
mailing list