[lld] r240862 - COFF: Use vector::erase instead of reallocating entire vector. NFC.

Rui Ueyama ruiu at google.com
Fri Jun 26 16:59:13 PDT 2015


Author: ruiu
Date: Fri Jun 26 18:59:13 2015
New Revision: 240862

URL: http://llvm.org/viewvc/llvm-project?rev=240862&view=rev
Log:
COFF: Use vector::erase instead of reallocating entire vector. NFC.

Modified:
    lld/trunk/COFF/Driver.cpp

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=240862&r1=240861&r2=240862&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Fri Jun 26 18:59:13 2015
@@ -485,17 +485,17 @@ bool LinkerDriver::link(llvm::ArrayRef<c
   // Windows specific -- Input files can be Windows resource files (.res files).
   // We invoke cvtres.exe to convert resource files to a regular COFF file
   // then link the result file normally.
-  auto IsResource = [](MemoryBufferRef MB) {
-    return identify_magic(MB.getBuffer()) == file_magic::windows_resource;
+  auto NotResource = [](MemoryBufferRef MB) {
+    return identify_magic(MB.getBuffer()) != file_magic::windows_resource;
   };
-  auto It = std::stable_partition(Inputs.begin(), Inputs.end(), IsResource);
-  if (It != Inputs.begin()) {
-    std::vector<MemoryBufferRef> Files(Inputs.begin(), It);
+  auto It = std::stable_partition(Inputs.begin(), Inputs.end(), NotResource);
+  if (It != Inputs.end()) {
+    std::vector<MemoryBufferRef> Files(It, Inputs.end());
     auto MBOrErr = convertResToCOFF(Files);
     if (MBOrErr.getError())
       return false;
     std::unique_ptr<MemoryBuffer> MB = std::move(MBOrErr.get());
-    Inputs = std::vector<MemoryBufferRef>(It, Inputs.end());
+    Inputs.erase(It, Inputs.end());
     Inputs.push_back(MB->getMemBufferRef());
     OwningMBs.push_back(std::move(MB)); // take ownership
   }





More information about the llvm-commits mailing list