[PATCH] D27667: COFF: Use a DenseSet instead of a map to atomic_flag to track which archive members have been read.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 11 19:26:39 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL289414: COFF: Use a DenseSet instead of a map to atomic_flag to track which archiveā€¦ (authored by pcc).

Changed prior to commit:
  https://reviews.llvm.org/D27667?vs=81040&id=81042#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27667

Files:
  lld/trunk/COFF/InputFiles.cpp
  lld/trunk/COFF/InputFiles.h


Index: lld/trunk/COFF/InputFiles.h
===================================================================
--- lld/trunk/COFF/InputFiles.h
+++ lld/trunk/COFF/InputFiles.h
@@ -12,6 +12,7 @@
 
 #include "lld/Core/LLVM.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/LTO/legacy/LTOModule.h"
 #include "llvm/Object/Archive.h"
@@ -91,7 +92,7 @@
 private:
   std::unique_ptr<Archive> File;
   std::string Filename;
-  std::map<uint64_t, std::atomic_flag> Seen;
+  llvm::DenseSet<uint64_t> Seen;
 };
 
 // .obj or .o file. This may be a member of an archive file.
Index: lld/trunk/COFF/InputFiles.cpp
===================================================================
--- lld/trunk/COFF/InputFiles.cpp
+++ lld/trunk/COFF/InputFiles.cpp
@@ -55,29 +55,19 @@
   // Parse a MemoryBufferRef as an archive file.
   File = check(Archive::create(MB), toString(this));
 
-  // Seen is a map from member files to boolean values. Initially
-  // all members are mapped to false, which indicates all these files
-  // are not read yet.
-  Error Err = Error::success();
-  for (auto &Child : File->children(Err))
-    Seen[Child.getChildOffset()].clear();
-  if (Err)
-    fatal(Err, toString(this));
-
   // Read the symbol table to construct Lazy objects.
   for (const Archive::Symbol &Sym : File->symbols())
     Symtab->addLazy(this, Sym);
 }
 
 // Returns a buffer pointing to a member file containing a given symbol.
-// This function is thread-safe.
 InputFile *ArchiveFile::getMember(const Archive::Symbol *Sym) {
   const Archive::Child &C =
       check(Sym->getMember(),
             "could not get the member for symbol " + Sym->getName());
 
   // Return an empty buffer if we have already returned the same buffer.
-  if (Seen[C.getChildOffset()].test_and_set())
+  if (!Seen.insert(C.getChildOffset()).second)
     return nullptr;
 
   MemoryBufferRef MB =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27667.81042.patch
Type: text/x-patch
Size: 1919 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161212/14e23476/attachment.bin>


More information about the llvm-commits mailing list