[PATCH] Inline short function using lambda to improve readability.

Rui Ueyama ruiu at google.com
Thu Apr 3 18:41:13 PDT 2014


  I'd think this is going to be the only place that the new coalescedAway()
  member function would be used, so I'd hesitate to add that to SymbolTable.

  How about this change? In this change we don't have the lambda inline.
  I feel it's more readable than before.

Hi Bigcheese, shankarke, kledzik,

http://llvm-reviews.chandlerc.com/D3286

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D3286?vs=8360&id=8361#toc

Files:
  lib/Core/Resolver.cpp

Index: lib/Core/Resolver.cpp
===================================================================
--- lib/Core/Resolver.cpp
+++ lib/Core/Resolver.cpp
@@ -29,24 +29,6 @@
 
 namespace lld {
 
-namespace {
-
-/// This is used as a filter function to std::remove_if to coalesced atoms.
-class AtomCoalescedAway {
-public:
-  explicit AtomCoalescedAway(SymbolTable &sym) : _symbolTable(sym) {}
-
-  bool operator()(const Atom *atom) const {
-    const Atom *rep = _symbolTable.replacement(atom);
-    return rep != atom;
-  }
-
-private:
-  SymbolTable &_symbolTable;
-};
-
-} // namespace
-
 void Resolver::handleFile(const File &file) {
   bool isEmpty = file.defined().empty() && file.undefined().empty() &&
                  file.sharedLibrary().empty() && file.absolute().empty();
@@ -403,8 +385,10 @@
 // remove from _atoms all coaleseced away atoms
 void Resolver::removeCoalescedAwayAtoms() {
   ScopedTask task(getDefaultDomain(), "removeCoalescedAwayAtoms");
-  _atoms.erase(std::remove_if(_atoms.begin(), _atoms.end(),
-                              AtomCoalescedAway(_symbolTable)),
+  auto coalescedAway = [&](const Atom *atom) {
+    return _symbolTable.replacement(atom) != atom;
+  };;
+  _atoms.erase(std::remove_if(_atoms.begin(), _atoms.end(), coalescedAway),
                _atoms.end());
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3286.2.patch
Type: text/x-patch
Size: 1309 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140403/f809bbb7/attachment.bin>


More information about the llvm-commits mailing list