[lld] e5b66a3 - lld-coff: Simplify a few lambda uses after 7975dd033cb9

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon May 24 17:26:58 PDT 2021


Author: David Blaikie
Date: 2021-05-24T17:26:46-07:00
New Revision: e5b66a373414036db22d19647d913c2571df2701

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

LOG: lld-coff: Simplify a few lambda uses after 7975dd033cb9

Added: 
    

Modified: 
    lld/COFF/Chunks.cpp

Removed: 
    


################################################################################
diff  --git a/lld/COFF/Chunks.cpp b/lld/COFF/Chunks.cpp
index ec64f650ad7a5..36d5f371326fe 100644
--- a/lld/COFF/Chunks.cpp
+++ b/lld/COFF/Chunks.cpp
@@ -824,18 +824,19 @@ void RVAFlagTableChunk::writeTo(uint8_t *buf) const {
     ulittle32_t rva;
     uint8_t flag;
   };
-  RVAFlag *begin = reinterpret_cast<RVAFlag *>(buf);
-  size_t cnt = 0;
-  for (const ChunkAndOffset &co : syms) {
-    begin[cnt].rva = co.inputChunk->getRVA() + co.offset;
-    begin[cnt].flag = 0;
-    ++cnt;
+  auto flags =
+      makeMutableArrayRef(reinterpret_cast<RVAFlag *>(buf), syms.size());
+  for (auto t : zip(syms, flags)) {
+    const auto &sym = std::get<0>(t);
+    auto &flag = std::get<1>(t);
+    flag.rva = sym.inputChunk->getRVA() + sym.offset;
+    flag.flag = 0;
   }
-  auto lt = [](RVAFlag &a, RVAFlag &b) { return a.rva < b.rva; };
-  auto eq = [](RVAFlag &a, RVAFlag &b) { return a.rva == b.rva; };
-  (void)eq;
-  std::sort(begin, begin + cnt, lt);
-  assert(std::unique(begin, begin + cnt, eq) == begin + cnt &&
+  llvm::sort(flags,
+             [](const RVAFlag &a, const RVAFlag &b) { return a.rva < b.rva; });
+  assert(llvm::unique(flags, [](const RVAFlag &a,
+                                const RVAFlag &b) { return a.rva == b.rva; }) ==
+             flags.end() &&
          "RVA tables should be de-duplicated");
 }
 


        


More information about the llvm-commits mailing list