[lld] r240665 - COFF: Use std::equal to compare two lists of relocations.

Rui Ueyama ruiu at google.com
Thu Jun 25 10:51:07 PDT 2015


Author: ruiu
Date: Thu Jun 25 12:51:07 2015
New Revision: 240665

URL: http://llvm.org/viewvc/llvm-project?rev=240665&view=rev
Log:
COFF: Use std::equal to compare two lists of relocations.

Modified:
    lld/trunk/COFF/Chunks.cpp

Modified: lld/trunk/COFF/Chunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.cpp?rev=240665&r1=240664&r2=240665&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.cpp (original)
+++ lld/trunk/COFF/Chunks.cpp Thu Jun 25 12:51:07 2015
@@ -186,24 +186,20 @@ bool SectionChunk::equals(const SectionC
     return false;
 
   // Compare relocations
-  const coff_relocation *Rel1 = Relocs.begin();
-  const coff_relocation *End = Relocs.end();
-  const coff_relocation *Rel2 = X->Relocs.begin();
-  for (; Rel1 != End; ++Rel1, ++Rel2) {
-    if (Rel1->Type != Rel2->Type)
+  auto Eq = [&](const coff_relocation &R1, const coff_relocation &R2) {
+    if (R1.Type != R2.Type)
       return false;
-    if (Rel1->VirtualAddress != Rel2->VirtualAddress)
+    if (R1.VirtualAddress != R2.VirtualAddress)
       return false;
-    SymbolBody *B1 = File->getSymbolBody(Rel1->SymbolTableIndex);
-    SymbolBody *B2 = X->File->getSymbolBody(Rel2->SymbolTableIndex);
+    SymbolBody *B1 = File->getSymbolBody(R1.SymbolTableIndex);
+    SymbolBody *B2 = X->File->getSymbolBody(R2.SymbolTableIndex);
     if (auto *C1 = dyn_cast<DefinedCOMDAT>(B1))
       if (auto *C2 = dyn_cast<DefinedCOMDAT>(B2))
         if (C1->getChunk() == C2->getChunk())
-          continue;
-    if (B1 != B2)
-      return false;
-  }
-  return true;
+          return true;
+    return B1 == B2;
+  };
+  return std::equal(Relocs.begin(), Relocs.end(), X->Relocs.begin(), Eq);
 }
 
 // Returns a pointer to this chunk or its replacement.





More information about the llvm-commits mailing list