[lld] r232088 - Rephrase find loop to use std::find_if

David Blaikie dblaikie at gmail.com
Thu Mar 12 12:46:22 PDT 2015


Author: dblaikie
Date: Thu Mar 12 14:46:21 2015
New Revision: 232088

URL: http://llvm.org/viewvc/llvm-project?rev=232088&view=rev
Log:
Rephrase find loop to use std::find_if

Avoids the need for an assert-only variable, among other benefits.

Modified:
    lld/trunk/include/lld/Core/File.h
    lld/trunk/lib/ReaderWriter/MachO/StubsPass.cpp

Modified: lld/trunk/include/lld/Core/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/File.h?rev=232088&r1=232087&r2=232088&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/File.h (original)
+++ lld/trunk/include/lld/Core/File.h Thu Mar 12 14:46:21 2015
@@ -126,7 +126,7 @@ public:
   /// object. There are four kinds of Atoms, so this iterator is templated on
   /// the four base Atom kinds.
   template <typename T>
-  class atom_iterator {
+  class atom_iterator : public std::iterator<std::forward_iterator_tag, T> {
   public:
     atom_iterator(const atom_collection<T> &c, const void *it)
               : _collection(c), _it(it) { }
@@ -139,8 +139,12 @@ public:
       return _collection.deref(_it);
     }
 
-    bool operator!=(const atom_iterator<T> &other) const {
-      return (this->_it != other._it);
+    friend bool operator==(const atom_iterator<T> &lhs, const atom_iterator<T> &rhs)  {
+      return lhs._it == rhs._it;
+    }
+
+    friend bool operator!=(const atom_iterator<T> &lhs, const atom_iterator<T> &rhs)  {
+      return !(lhs == rhs);
     }
 
     atom_iterator<T> &operator++() {
@@ -152,7 +156,6 @@ public:
     const void               *_it;
   };
 
-
   /// \brief Must be implemented to return the atom_collection object for
   /// all DefinedAtoms in this File.
   virtual const atom_collection<DefinedAtom> &defined() const = 0;

Modified: lld/trunk/lib/ReaderWriter/MachO/StubsPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/StubsPass.cpp?rev=232088&r1=232087&r2=232088&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/StubsPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/StubsPass.cpp Thu Mar 12 14:46:21 2015
@@ -264,17 +264,13 @@ public:
     mergedFile->addAtom(*helperCacheNLPAtom);
 
     // Add reference to dyld_stub_binder in libSystem.dylib
-    bool binderFound = false;
-    for (const SharedLibraryAtom *atom : mergedFile->sharedLibrary()) {
-      if (atom->name().equals(_stubInfo.binderSymbolName)) {
-        addReference(helperBinderNLPAtom,
-                     _stubInfo.nonLazyPointerReferenceToBinder, atom);
-        binderFound = true;
-        break;
-      }
-    }
-    assert(binderFound && "dyld_stub_binder not found");
-    (void)binderFound;
+    auto I = std::find_if(
+        mergedFile->sharedLibrary().begin(), mergedFile->sharedLibrary().end(),
+        [&](const SharedLibraryAtom *atom) {
+          return atom->name().equals(_stubInfo.binderSymbolName);
+        });
+    assert(I != mergedFile->sharedLibrary().end() && "dyld_stub_binder not found");
+    addReference(helperBinderNLPAtom, _stubInfo.nonLazyPointerReferenceToBinder, *I);
 
     // Sort targets by name, so stubs and lazy pointers are consistent
     std::vector<const Atom *> targetsNeedingStubs;





More information about the llvm-commits mailing list