[llvm] Eliminate pointless copies (PR #95097)

Braden Helmer via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 12 03:39:08 PDT 2024


https://github.com/bradenhelmer updated https://github.com/llvm/llvm-project/pull/95097

>From 0785efda9f726978f9a2a6c278c9b37d3728b548 Mon Sep 17 00:00:00 2001
From: Braden Helmer <bradenhelmeraus at gmail.com>
Date: Tue, 11 Jun 2024 06:52:05 -0400
Subject: [PATCH] Eliminate pointless copies

---
 llvm/include/llvm/Object/ELFTypes.h                 | 4 ++--
 llvm/include/llvm/Passes/StandardInstrumentations.h | 6 +++---
 llvm/include/llvm/Support/Caching.h                 | 5 ++---
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/llvm/include/llvm/Object/ELFTypes.h b/llvm/include/llvm/Object/ELFTypes.h
index 4ab23e4ea81b1..a4f3ad6348c10 100644
--- a/llvm/include/llvm/Object/ELFTypes.h
+++ b/llvm/include/llvm/Object/ELFTypes.h
@@ -717,14 +717,14 @@ template <class ELFT> class Elf_Note_Iterator_Impl {
     advanceNhdr(NhdrPos, NoteSize);
     return *this;
   }
-  bool operator==(Elf_Note_Iterator_Impl Other) const {
+  bool operator==(const Elf_Note_Iterator_Impl &Other) const {
     if (!Nhdr && Other.Err)
       (void)(bool)(*Other.Err);
     if (!Other.Nhdr && Err)
       (void)(bool)(*Err);
     return Nhdr == Other.Nhdr;
   }
-  bool operator!=(Elf_Note_Iterator_Impl Other) const {
+  bool operator!=(const Elf_Note_Iterator_Impl &Other) const {
     return !(*this == Other);
   }
   Elf_Note_Impl<ELFT> operator*() const {
diff --git a/llvm/include/llvm/Passes/StandardInstrumentations.h b/llvm/include/llvm/Passes/StandardInstrumentations.h
index 84d1b541171bf..b3caa689c84b4 100644
--- a/llvm/include/llvm/Passes/StandardInstrumentations.h
+++ b/llvm/include/llvm/Passes/StandardInstrumentations.h
@@ -382,13 +382,13 @@ class EmptyData {
 template <typename T>
 class FuncDataT : public OrderedChangedData<BlockDataT<T>> {
 public:
-  FuncDataT(std::string S) : EntryBlockName(S) {}
+  FuncDataT(StringRef S) : EntryBlockName(S) {}
 
   // Return the name of the entry block
-  std::string getEntryBlockName() const { return EntryBlockName; }
+  StringRef getEntryBlockName() const { return EntryBlockName; }
 
 protected:
-  std::string EntryBlockName;
+  StringRef EntryBlockName;
 };
 
 // The data saved for comparing IRs.
diff --git a/llvm/include/llvm/Support/Caching.h b/llvm/include/llvm/Support/Caching.h
index 4fa57cc92e51f..cdf2bc2ecee19 100644
--- a/llvm/include/llvm/Support/Caching.h
+++ b/llvm/include/llvm/Support/Caching.h
@@ -27,11 +27,10 @@ class MemoryBuffer;
 /// that can be done by deriving from this class and overriding the destructor.
 class CachedFileStream {
 public:
-  CachedFileStream(std::unique_ptr<raw_pwrite_stream> OS,
-                   std::string OSPath = "")
+  CachedFileStream(std::unique_ptr<raw_pwrite_stream> OS, StringRef OSPath = "")
       : OS(std::move(OS)), ObjectPathName(OSPath) {}
   std::unique_ptr<raw_pwrite_stream> OS;
-  std::string ObjectPathName;
+  StringRef ObjectPathName;
   virtual ~CachedFileStream() = default;
 };
 



More information about the llvm-commits mailing list