[lld] r320125 - Prefer `ArrayRef` over `const std::vector&`

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 7 17:09:21 PST 2017


Author: sbc
Date: Thu Dec  7 17:09:21 2017
New Revision: 320125

URL: http://llvm.org/viewvc/llvm-project?rev=320125&view=rev
Log:
Prefer `ArrayRef` over `const std::vector&`

Differential Revision: https://reviews.llvm.org/D40993

Modified:
    lld/trunk/COFF/Driver.h
    lld/trunk/COFF/DriverUtils.cpp
    lld/trunk/COFF/ICF.cpp
    lld/trunk/COFF/InputFiles.h
    lld/trunk/COFF/MarkLive.cpp
    lld/trunk/COFF/PDB.cpp
    lld/trunk/COFF/SymbolTable.cpp
    lld/trunk/COFF/Writer.h
    lld/trunk/include/lld/Core/LinkingContext.h
    lld/trunk/wasm/InputFiles.h
    lld/trunk/wasm/OutputSections.cpp
    lld/trunk/wasm/OutputSections.h

Modified: lld/trunk/COFF/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.h?rev=320125&r1=320124&r2=320125&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.h (original)
+++ lld/trunk/COFF/Driver.h Thu Dec  7 17:09:21 2017
@@ -36,10 +36,10 @@ using llvm::COFF::WindowsSubsystem;
 using llvm::Optional;
 
 // Implemented in MarkLive.cpp.
-void markLive(const std::vector<Chunk *> &Chunks);
+void markLive(ArrayRef<Chunk *> Chunks);
 
 // Implemented in ICF.cpp.
-void doICF(const std::vector<Chunk *> &Chunks);
+void doICF(ArrayRef<Chunk *> Chunks);
 
 class COFFOptTable : public llvm::opt::OptTable {
 public:
@@ -171,7 +171,7 @@ void assignExportOrdinals();
 void checkFailIfMismatch(StringRef Arg);
 
 // Convert Windows resource files (.res files) to a .obj file.
-MemoryBufferRef convertResToCOFF(const std::vector<MemoryBufferRef> &MBs);
+MemoryBufferRef convertResToCOFF(ArrayRef<MemoryBufferRef> MBs);
 
 void runMSVCLinker(std::string Rsp, ArrayRef<StringRef> Objects);
 

Modified: lld/trunk/COFF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DriverUtils.cpp?rev=320125&r1=320124&r2=320125&view=diff
==============================================================================
--- lld/trunk/COFF/DriverUtils.cpp (original)
+++ lld/trunk/COFF/DriverUtils.cpp Thu Dec  7 17:09:21 2017
@@ -642,7 +642,7 @@ void checkFailIfMismatch(StringRef Arg)
 }
 
 // Convert Windows resource files (.res files) to a .obj file.
-MemoryBufferRef convertResToCOFF(const std::vector<MemoryBufferRef> &MBs) {
+MemoryBufferRef convertResToCOFF(ArrayRef<MemoryBufferRef> MBs) {
   object::WindowsResourceParser Parser;
 
   for (MemoryBufferRef MB : MBs) {

Modified: lld/trunk/COFF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/ICF.cpp?rev=320125&r1=320124&r2=320125&view=diff
==============================================================================
--- lld/trunk/COFF/ICF.cpp (original)
+++ lld/trunk/COFF/ICF.cpp Thu Dec  7 17:09:21 2017
@@ -36,7 +36,7 @@ namespace coff {
 
 class ICF {
 public:
-  void run(const std::vector<Chunk *> &V);
+  void run(ArrayRef<Chunk *> V);
 
 private:
   void segregate(size_t Begin, size_t End, bool Constant);
@@ -206,7 +206,7 @@ void ICF::forEachClass(std::function<voi
 // Merge identical COMDAT sections.
 // Two sections are considered the same if their section headers,
 // contents and relocations are all the same.
-void ICF::run(const std::vector<Chunk *> &Vec) {
+void ICF::run(ArrayRef<Chunk *> Vec) {
   // Collect only mergeable sections and group by hash value.
   uint32_t NextId = 1;
   for (Chunk *C : Vec) {
@@ -257,7 +257,7 @@ void ICF::run(const std::vector<Chunk *>
 }
 
 // Entry point to ICF.
-void doICF(const std::vector<Chunk *> &Chunks) { ICF().run(Chunks); }
+void doICF(ArrayRef<Chunk *> Chunks) { ICF().run(Chunks); }
 
 } // namespace coff
 } // namespace lld

Modified: lld/trunk/COFF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.h?rev=320125&r1=320124&r2=320125&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.h (original)
+++ lld/trunk/COFF/InputFiles.h Thu Dec  7 17:09:21 2017
@@ -108,9 +108,9 @@ public:
   static bool classof(const InputFile *F) { return F->kind() == ObjectKind; }
   void parse() override;
   MachineTypes getMachineType() override;
-  std::vector<Chunk *> &getChunks() { return Chunks; }
-  std::vector<SectionChunk *> &getDebugChunks() { return DebugChunks; }
-  std::vector<Symbol *> &getSymbols() { return Symbols; }
+  ArrayRef<Chunk *> getChunks() { return Chunks; }
+  ArrayRef<SectionChunk *> getDebugChunks() { return DebugChunks; }
+  ArrayRef<Symbol *> getSymbols() { return Symbols; }
 
   // Returns a Symbol object for the SymbolIndex'th symbol in the
   // underlying object file.
@@ -217,7 +217,7 @@ class BitcodeFile : public InputFile {
 public:
   explicit BitcodeFile(MemoryBufferRef M) : InputFile(BitcodeKind, M) {}
   static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; }
-  std::vector<Symbol *> &getSymbols() { return SymbolBodies; }
+  ArrayRef<Symbol *> getSymbols() { return SymbolBodies; }
   MachineTypes getMachineType() override;
   static std::vector<BitcodeFile *> Instances;
   std::unique_ptr<llvm::lto::InputFile> Obj;

Modified: lld/trunk/COFF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/MarkLive.cpp?rev=320125&r1=320124&r2=320125&view=diff
==============================================================================
--- lld/trunk/COFF/MarkLive.cpp (original)
+++ lld/trunk/COFF/MarkLive.cpp Thu Dec  7 17:09:21 2017
@@ -18,7 +18,7 @@ namespace coff {
 // Set live bit on for each reachable chunk. Unmarked (unreachable)
 // COMDAT chunks will be ignored by Writer, so they will be excluded
 // from the final output.
-void markLive(const std::vector<Chunk *> &Chunks) {
+void markLive(ArrayRef<Chunk *> Chunks) {
   // We build up a worklist of sections which have been marked as live. We only
   // push into the worklist when we discover an unmarked section, and we mark
   // as we push, so sections never appear twice in the list.

Modified: lld/trunk/COFF/PDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/PDB.cpp?rev=320125&r1=320124&r2=320125&view=diff
==============================================================================
--- lld/trunk/COFF/PDB.cpp (original)
+++ lld/trunk/COFF/PDB.cpp Thu Dec  7 17:09:21 2017
@@ -136,7 +136,7 @@ private:
 };
 }
 
-static SectionChunk *findByName(std::vector<SectionChunk *> &Sections,
+static SectionChunk *findByName(ArrayRef<SectionChunk *> Sections,
                                 StringRef Name) {
   for (SectionChunk *C : Sections)
     if (C->getSectionName() == Name)

Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=320125&r1=320124&r2=320125&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Thu Dec  7 17:09:21 2017
@@ -291,7 +291,7 @@ DefinedImportThunk *SymbolTable::addImpo
 std::vector<Chunk *> SymbolTable::getChunks() {
   std::vector<Chunk *> Res;
   for (ObjFile *File : ObjFile::Instances) {
-    std::vector<Chunk *> &V = File->getChunks();
+    ArrayRef<Chunk *> V = File->getChunks();
     Res.insert(Res.end(), V.begin(), V.end());
   }
   return Res;

Modified: lld/trunk/COFF/Writer.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.h?rev=320125&r1=320124&r2=320125&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.h (original)
+++ lld/trunk/COFF/Writer.h Thu Dec  7 17:09:21 2017
@@ -34,7 +34,7 @@ public:
   void setFileOffset(uint64_t);
   void addChunk(Chunk *C);
   llvm::StringRef getName() { return Name; }
-  std::vector<Chunk *> &getChunks() { return Chunks; }
+  ArrayRef<Chunk *> getChunks() { return Chunks; }
   void addPermissions(uint32_t C);
   void setPermissions(uint32_t C);
   uint32_t getPermissions() { return Header.Characteristics & PermMask; }

Modified: lld/trunk/include/lld/Core/LinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/LinkingContext.h?rev=320125&r1=320124&r2=320125&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/LinkingContext.h (original)
+++ lld/trunk/include/lld/Core/LinkingContext.h Thu Dec  7 17:09:21 2017
@@ -62,7 +62,7 @@ public:
   /// of DefinedAtoms that should be marked live (along with all Atoms they
   /// reference). Only Atoms with scope scopeLinkageUnit or scopeGlobal can
   /// be kept live using this method.
-  const std::vector<StringRef> &deadStripRoots() const {
+  ArrayRef<StringRef> deadStripRoots() const {
     return _deadStripRoots;
   }
 
@@ -106,7 +106,7 @@ public:
   /// options which are used to configure LLVM's command line settings.
   /// For instance the -debug-only XXX option can be used to dynamically
   /// trace different parts of LLVM and lld.
-  const std::vector<const char *> &llvmOptions() const { return _llvmOptions; }
+  ArrayRef<const char *> llvmOptions() const { return _llvmOptions; }
 
   /// \name Methods used by Drivers to configure TargetInfo
   /// @{

Modified: lld/trunk/wasm/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputFiles.h?rev=320125&r1=320124&r2=320125&view=diff
==============================================================================
--- lld/trunk/wasm/InputFiles.h (original)
+++ lld/trunk/wasm/InputFiles.h Thu Dec  7 17:09:21 2017
@@ -112,7 +112,7 @@ public:
   std::vector<uint32_t> TypeMap;
   std::vector<InputSegment *> Segments;
 
-  const std::vector<Symbol *> &getSymbols() { return Symbols; }
+  ArrayRef<Symbol *> getSymbols() { return Symbols; }
 
 private:
   Symbol *createDefined(const WasmSymbol &Sym,

Modified: lld/trunk/wasm/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/OutputSections.cpp?rev=320125&r1=320124&r2=320125&view=diff
==============================================================================
--- lld/trunk/wasm/OutputSections.cpp (original)
+++ lld/trunk/wasm/OutputSections.cpp Thu Dec  7 17:09:21 2017
@@ -109,7 +109,7 @@ static void applyRelocation(uint8_t *Buf
 }
 
 static void applyRelocations(uint8_t *Buf,
-                             const std::vector<OutputRelocation> &Relocs) {
+                             ArrayRef<OutputRelocation> Relocs) {
   log("applyRelocations: count=" + Twine(Relocs.size()));
   for (const OutputRelocation &Reloc : Relocs) {
     applyRelocation(Buf, Reloc);
@@ -188,7 +188,7 @@ void OutputSection::createHeader(size_t
       " total=" + Twine(getSize()));
 }
 
-CodeSection::CodeSection(uint32_t NumFunctions, std::vector<ObjFile *> &Objs)
+CodeSection::CodeSection(uint32_t NumFunctions, ArrayRef<ObjFile *> Objs)
     : OutputSection(WASM_SEC_CODE), InputObjects(Objs) {
   raw_string_ostream OS(CodeSectionHeader);
   writeUleb128(OS, NumFunctions, "function count");
@@ -263,7 +263,7 @@ void CodeSection::writeRelocations(raw_o
       writeReloc(OS, Reloc);
 }
 
-DataSection::DataSection(std::vector<OutputSegment *> &Segments)
+DataSection::DataSection(ArrayRef<OutputSegment *> Segments)
     : OutputSection(WASM_SEC_DATA), Segments(Segments) {
   raw_string_ostream OS(DataSectionHeader);
 

Modified: lld/trunk/wasm/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/OutputSections.h?rev=320125&r1=320124&r2=320125&view=diff
==============================================================================
--- lld/trunk/wasm/OutputSections.h (original)
+++ lld/trunk/wasm/OutputSections.h Thu Dec  7 17:09:21 2017
@@ -105,21 +105,21 @@ public:
 
 class CodeSection : public OutputSection {
 public:
-  explicit CodeSection(uint32_t NumFunctions, std::vector<ObjFile *> &Objs);
+  explicit CodeSection(uint32_t NumFunctions, ArrayRef<ObjFile *> Objs);
   size_t getSize() const override { return Header.size() + BodySize; }
   void writeTo(uint8_t *Buf) override;
   uint32_t numRelocations() const override;
   void writeRelocations(raw_ostream &OS) const override;
 
 protected:
-  std::vector<ObjFile *> &InputObjects;
+  ArrayRef<ObjFile *> InputObjects;
   std::string CodeSectionHeader;
   size_t BodySize = 0;
 };
 
 class DataSection : public OutputSection {
 public:
-  explicit DataSection(std::vector<OutputSegment *> &Segments);
+  explicit DataSection(ArrayRef<OutputSegment *> Segments);
   size_t getSize() const override { return Header.size() + BodySize; }
   void writeTo(uint8_t *Buf) override;
   uint32_t numRelocations() const override { return Relocations.size(); }
@@ -127,7 +127,7 @@ public:
 
 protected:
   std::vector<OutputRelocation> Relocations;
-  std::vector<OutputSegment *> &Segments;
+  ArrayRef<OutputSegment *> Segments;
   std::string DataSectionHeader;
   size_t BodySize = 0;
 };




More information about the llvm-commits mailing list