[PATCH] Return a vector rather than mutating a given one.
Rui Ueyama
ruiu at google.com
Thu Apr 3 16:18:06 PDT 2014
Hi Bigcheese, shankarke, kledzik,
This is cleaner and as efficient as before.
http://llvm-reviews.chandlerc.com/D3284
Files:
include/lld/Core/SymbolTable.h
lib/Core/Resolver.cpp
lib/Core/SymbolTable.cpp
Index: include/lld/Core/SymbolTable.h
===================================================================
--- include/lld/Core/SymbolTable.h
+++ include/lld/Core/SymbolTable.h
@@ -58,10 +58,10 @@
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();
Index: lib/Core/Resolver.cpp
===================================================================
--- lib/Core/Resolver.cpp
+++ lib/Core/Resolver.cpp
@@ -74,19 +74,16 @@
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);
@@ -360,8 +357,7 @@
// 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(
Index: lib/Core/SymbolTable.cpp
===================================================================
--- lib/Core/SymbolTable.cpp
+++ lib/Core/SymbolTable.cpp
@@ -392,27 +392,32 @@
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);
if (const auto undef = dyn_cast<const UndefinedAtom>(atom)) {
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3284.1.patch
Type: text/x-patch
Size: 3612 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140403/ca95856c/attachment.bin>
More information about the llvm-commits
mailing list