[lld] 7e6d675 - [lld-macho] Avoid unnecessary shared_ptr in DylibFile ctor

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 12 19:51:05 PDT 2020


Author: Jez Ng
Date: 2020-08-12T19:50:12-07:00
New Revision: 7e6d6754998058457c2ec94e89daf7f998d970a0

URL: https://github.com/llvm/llvm-project/commit/7e6d6754998058457c2ec94e89daf7f998d970a0
DIFF: https://github.com/llvm/llvm-project/commit/7e6d6754998058457c2ec94e89daf7f998d970a0.diff

LOG: [lld-macho] Avoid unnecessary shared_ptr in DylibFile ctor

DylibFile doesn't store a pointer to its InterfaceFile
parameter, so there's no need to use a shared_ptr.

Reviewed By: #lld-macho, compnerd

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

Added: 
    

Modified: 
    lld/MachO/Driver.cpp
    lld/MachO/InputFiles.cpp
    lld/MachO/InputFiles.h

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index ccbd77d7ff05..3b45dad1600e 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -235,7 +235,7 @@ static void addFile(StringRef path) {
     if (!result)
       return;
 
-    inputFiles.push_back(make<DylibFile>(std::move(*result)));
+    inputFiles.push_back(make<DylibFile>(**result));
     break;
   }
   default:

diff  --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index 03573868146e..5e0c9e0679da 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -396,13 +396,12 @@ DylibFile::DylibFile(MemoryBufferRef mb, DylibFile *umbrella)
   }
 }
 
-DylibFile::DylibFile(std::shared_ptr<llvm::MachO::InterfaceFile> interface,
-                     DylibFile *umbrella)
+DylibFile::DylibFile(const InterfaceFile &interface, DylibFile *umbrella)
     : InputFile(DylibKind, MemoryBufferRef()) {
   if (umbrella == nullptr)
     umbrella = this;
 
-  dylibName = saver.save(interface->getInstallName());
+  dylibName = saver.save(interface.getInstallName());
   auto addSymbol = [&](const Twine &name) -> void {
     symbols.push_back(symtab->addDylib(saver.save(name), umbrella,
                                        /*isWeakDef=*/false,
@@ -410,7 +409,7 @@ DylibFile::DylibFile(std::shared_ptr<llvm::MachO::InterfaceFile> interface,
   };
   // TODO(compnerd) filter out symbols based on the target platform
   // TODO: handle weak defs, thread locals
-  for (const auto symbol : interface->symbols()) {
+  for (const auto symbol : interface.symbols()) {
     if (!symbol->getArchitectures().has(config->arch))
       continue;
 
@@ -435,8 +434,8 @@ DylibFile::DylibFile(std::shared_ptr<llvm::MachO::InterfaceFile> interface,
   // TODO(compnerd) properly represent the hierarchy of the documents as it is
   // in theory possible to have re-exported dylibs from re-exported dylibs which
   // should be parent'ed to the child.
-  for (auto document : interface->documents())
-    reexported.push_back(make<DylibFile>(document, umbrella));
+  for (const std::shared_ptr<InterfaceFile> &intf : interface.documents())
+    reexported.push_back(make<DylibFile>(*intf, umbrella));
 }
 
 ArchiveFile::ArchiveFile(std::unique_ptr<llvm::object::Archive> &&f)

diff  --git a/lld/MachO/InputFiles.h b/lld/MachO/InputFiles.h
index 2aa03014cd50..3a7795254f9a 100644
--- a/lld/MachO/InputFiles.h
+++ b/lld/MachO/InputFiles.h
@@ -84,7 +84,7 @@ class OpaqueFile : public InputFile {
 // .dylib file
 class DylibFile : public InputFile {
 public:
-  explicit DylibFile(std::shared_ptr<llvm::MachO::InterfaceFile> interface,
+  explicit DylibFile(const llvm::MachO::InterfaceFile &interface,
                      DylibFile *umbrella = nullptr);
 
   // Mach-O dylibs can re-export other dylibs as sub-libraries, meaning that the


        


More information about the llvm-commits mailing list