[lld] 36f32ff - [lld-macho] Minor clean up: use .find() to check for key existence rather than [], which would create a new entry.

Vy Nguyen via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 3 14:17:30 PST 2022


Author: Vy Nguyen
Date: 2022-02-03T17:17:14-05:00
New Revision: 36f32ffd2abfec44b7f56554f05219324b9bbbc2

URL: https://github.com/llvm/llvm-project/commit/36f32ffd2abfec44b7f56554f05219324b9bbbc2
DIFF: https://github.com/llvm/llvm-project/commit/36f32ffd2abfec44b7f56554f05219324b9bbbc2.diff

LOG: [lld-macho] Minor clean up: use .find() to check for key existence rather than [], which would create a new entry.

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

Added: 
    

Modified: 
    lld/MachO/Driver.cpp

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index c88f2482855fd..58a443664b7c5 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -267,8 +267,9 @@ static InputFile *addFile(StringRef path, ForceLoad forceLoadArchive,
     // We don't take a reference to cachedFile here because the
     // loadArchiveMember() call below may recursively call addFile() and
     // invalidate this reference.
-    if (ArchiveFile *cachedFile = loadedArchives[path])
-      return cachedFile;
+    auto entry = loadedArchives.find(path);
+    if (entry != loadedArchives.end())
+      return entry->second;
 
     std::unique_ptr<object::Archive> archive = CHECK(
         object::Archive::create(mbref), path + ": failed to parse archive");


        


More information about the llvm-commits mailing list