[lld] r205590 - Return a vector rather than mutating a given one.

Rui Ueyama ruiu at google.com
Thu Apr 3 17:15:52 PDT 2014


Author: ruiu
Date: Thu Apr  3 19:15:52 2014
New Revision: 205590

URL: http://llvm.org/viewvc/llvm-project?rev=205590&view=rev
Log:
Return a vector rather than mutating a given one.

This is cleaner and as efficient as before.

Differential Revision: http://llvm-reviews.chandlerc.com/D3284

Modified:
    lld/trunk/include/lld/Core/SymbolTable.h
    lld/trunk/lib/Core/Resolver.cpp
    lld/trunk/lib/Core/SymbolTable.cpp

Modified: lld/trunk/include/lld/Core/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/SymbolTable.h?rev=205590&r1=205589&r2=205590&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/SymbolTable.h (original)
+++ lld/trunk/include/lld/Core/SymbolTable.h Thu Apr  3 19:15:52 2014
@@ -58,10 +58,10 @@ public:
   const Atom *findByName(StringRef sym);
 
   /// @brief returns vector of remaining UndefinedAtoms
-  void undefines(std::vector<const UndefinedAtom *>&);
+  std::vector<const UndefinedAtom *> undefines();
 
   /// returns vector of tentative definitions
-  void tentativeDefinitions(std::vector<StringRef> &);
+  std::vector<StringRef> tentativeDefinitions();
 
   /// @brief count of by-name entries in symbol table
   unsigned int size();

Modified: lld/trunk/lib/Core/Resolver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Resolver.cpp?rev=205590&r1=205589&r2=205590&view=diff
==============================================================================
--- lld/trunk/lib/Core/Resolver.cpp (original)
+++ lld/trunk/lib/Core/Resolver.cpp Thu Apr  3 19:15:52 2014
@@ -74,19 +74,16 @@ void Resolver::forEachUndefines(UndefCal
   int64_t undefineGenCount = 0;
   do {
     undefineGenCount = _symbolTable.size();
-    std::vector<const UndefinedAtom *> undefines;
-    _symbolTable.undefines(undefines);
-    for (const UndefinedAtom *undefAtom : undefines) {
+    for (const UndefinedAtom *undefAtom : _symbolTable.undefines()) {
       StringRef undefName = undefAtom->name();
       // load for previous undefine may also have loaded this undefine
       if (!_symbolTable.isDefined(undefName))
         callback(undefName, false);
     }
+
     // search libraries for overrides of common symbols
     if (searchForOverrides) {
-      std::vector<StringRef> tentDefNames;
-      _symbolTable.tentativeDefinitions(tentDefNames);
-      for (StringRef tentDefName : tentDefNames) {
+      for (StringRef tentDefName : _symbolTable.tentativeDefinitions()) {
         // Load for previous tentative may also have loaded
         // something that overrode this tentative, so always check.
         const Atom *curAtom = _symbolTable.findByName(tentDefName);
@@ -359,8 +356,7 @@ void Resolver::deadStripOptimize() {
 // error out if some undefines remain
 bool Resolver::checkUndefines() {
   // build vector of remaining undefined symbols
-  std::vector<const UndefinedAtom *> undefinedAtoms;
-  _symbolTable.undefines(undefinedAtoms);
+  std::vector<const UndefinedAtom *> undefinedAtoms = _symbolTable.undefines();
   if (_context.deadStrip()) {
     // When dead code stripping, we don't care if dead atoms are undefined.
     undefinedAtoms.erase(

Modified: lld/trunk/lib/Core/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/SymbolTable.cpp?rev=205590&r1=205589&r2=205590&view=diff
==============================================================================
--- lld/trunk/lib/Core/SymbolTable.cpp (original)
+++ lld/trunk/lib/Core/SymbolTable.cpp Thu Apr  3 19:15:52 2014
@@ -392,7 +392,8 @@ unsigned int SymbolTable::size() {
   return _nameTable.size();
 }
 
-void SymbolTable::undefines(std::vector<const UndefinedAtom *> &undefs) {
+std::vector<const UndefinedAtom *> SymbolTable::undefines() {
+  std::vector<const UndefinedAtom *> ret;
   for (auto it : _nameTable) {
     const Atom *atom = it.second;
     assert(atom != nullptr);
@@ -400,19 +401,23 @@ void SymbolTable::undefines(std::vector<
       AtomToAtom::iterator pos = _replacedAtoms.find(undef);
       if (pos != _replacedAtoms.end())
         continue;
-      undefs.push_back(undef);
+      ret.push_back(undef);
     }
   }
+  return ret;
 }
 
-void SymbolTable::tentativeDefinitions(std::vector<StringRef> &names) {
+std::vector<StringRef> SymbolTable::tentativeDefinitions() {
+  std::vector<StringRef> ret;
   for (auto entry : _nameTable) {
     const Atom *atom = entry.second;
     StringRef name   = entry.first;
     assert(atom != nullptr);
     if (const DefinedAtom *defAtom = dyn_cast<DefinedAtom>(atom))
       if (defAtom->merge() == DefinedAtom::mergeAsTentative)
-        names.push_back(name);
+        ret.push_back(name);
   }
+  return ret;
 }
+
 } // namespace lld





More information about the llvm-commits mailing list