From 6ffe42eee5f5bcaeb94cfacbf76274fabe7f1114 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Mon, 2 Jun 2014 08:06:57 +0000 Subject: [PATCH] Simplify markLive(). Reference::target() never returns a nullptr, so NULL check is not needed and is more harmful than doing nothing. No functionality change. llvm-svn: 210008 --- lld/include/lld/Core/Resolver.h | 2 +- lld/lib/Core/Resolver.cpp | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lld/include/lld/Core/Resolver.h b/lld/include/lld/Core/Resolver.h index 22af4e21437e..0bb1223f15e1 100644 --- a/lld/include/lld/Core/Resolver.h +++ b/lld/include/lld/Core/Resolver.h @@ -67,7 +67,7 @@ private: void checkDylibSymbolCollisions(); void forEachUndefines(bool searchForOverrides, UndefCallback callback); - void markLive(const Atom &atom); + void markLive(const Atom *atom); void addAtoms(const std::vector&); class MergedFile : public MutableFile { diff --git a/lld/lib/Core/Resolver.cpp b/lld/lib/Core/Resolver.cpp index 6ed35598d60b..bf4b4842ab83 100644 --- a/lld/lib/Core/Resolver.cpp +++ b/lld/lib/Core/Resolver.cpp @@ -305,17 +305,16 @@ void Resolver::updateReferences() { } // For dead code stripping, recursively mark atoms "live" -void Resolver::markLive(const Atom &atom) { +void Resolver::markLive(const Atom *atom) { // Mark the atom is live. If it's already marked live, then stop recursion. - auto exists = _liveAtoms.insert(&atom); + auto exists = _liveAtoms.insert(atom); if (!exists.second) return; // Mark all atoms it references as live - if (const DefinedAtom *defAtom = dyn_cast(&atom)) + if (const DefinedAtom *defAtom = dyn_cast(atom)) for (const Reference *ref : *defAtom) - if (const Atom *target = ref->target()) - markLive(*target); + markLive(ref->target()); } // remove all atoms not actually used @@ -342,7 +341,7 @@ void Resolver::deadStripOptimize() { // mark all roots as live, and recursively all atoms they reference for (const Atom *dsrAtom : _deadStripRoots) - markLive(*dsrAtom); + markLive(dsrAtom); // now remove all non-live atoms from _atoms _atoms.erase(std::remove_if(_atoms.begin(), _atoms.end(), [&](const Atom *a) {