aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2004-11-19 03:18:22 +0000
committerReid Spencer <rspencer@reidspencer.com>2004-11-19 03:18:22 +0000
commit7783e8ad69a2ac14ba50f6b015806b48c4131240 (patch)
tree599c39598e9a847f48572bfd44d854601edaf70f
parent3cf2c32202c9bccfa3005c5b1edcecc69dd64598 (diff)
downloadexternal_llvm-7783e8ad69a2ac14ba50f6b015806b48c4131240.tar.gz
external_llvm-7783e8ad69a2ac14ba50f6b015806b48c4131240.tar.bz2
external_llvm-7783e8ad69a2ac14ba50f6b015806b48c4131240.zip
Make findModulesDefiningSymbols modify its symbols argument so we can \
eliminate symbols defined by the archive efficiently git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17976 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Bytecode/Archive.h9
-rw-r--r--lib/Archive/ArchiveReader.cpp17
-rw-r--r--lib/Bytecode/Archive/ArchiveReader.cpp17
3 files changed, 34 insertions, 9 deletions
diff --git a/include/llvm/Bytecode/Archive.h b/include/llvm/Bytecode/Archive.h
index 67615b3bef..943d979cac 100644
--- a/include/llvm/Bytecode/Archive.h
+++ b/include/llvm/Bytecode/Archive.h
@@ -396,11 +396,14 @@ class Archive {
/// more than one symbol at a time. If \p symbols contains a list of
/// undefined symbols in some module, then calling this method is like
/// making one complete pass through the archive to resolve symbols but is
- /// more efficient than looking at the individual members.
+ /// more efficient than looking at the individual members. Note that on
+ /// exit, the symbols resolved by this method will be removed from \p
+ /// symbols to ensure they are not re-searched on a subsequent call. If
+ /// you need to retain the list of symbols, make a copy.
/// @brief Look up multiple symbols in the archive.
void findModulesDefiningSymbols(
- const std::set<std::string>& symbols, ///< Symbols to be sought
- std::set<ModuleProvider*>& modules ///< The modules matching \p symbols
+ std::set<std::string>& symbols, ///< Symbols to be sought
+ std::set<ModuleProvider*>& modules ///< The modules matching \p symbols
);
/// @}
diff --git a/lib/Archive/ArchiveReader.cpp b/lib/Archive/ArchiveReader.cpp
index 615df2bf5f..6f5b9d36ed 100644
--- a/lib/Archive/ArchiveReader.cpp
+++ b/lib/Archive/ArchiveReader.cpp
@@ -407,7 +407,7 @@ Archive::findModuleDefiningSymbol(const std::string& symbol) {
// Look up multiple symbols in the symbol table and return a set of
// ModuleProviders that define those symbols.
void
-Archive::findModulesDefiningSymbols(const std::set<std::string>& symbols,
+Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
std::set<ModuleProvider*>& result)
{
assert(mapfile && base && "Can't findModulesDefiningSymbols on new archive");
@@ -462,11 +462,22 @@ Archive::findModulesDefiningSymbols(const std::set<std::string>& symbols,
// At this point we have a valid symbol table (one way or another) so we
// just use it to quickly find the symbols requested.
- for (std::set<std::string>::const_iterator I=symbols.begin(),
- E=symbols.end(); I != E; ++I) {
+ for (std::set<std::string>::iterator I=symbols.begin(),
+ E=symbols.end(); I != E;) {
+ // See if this symbol exists
ModuleProvider* mp = findModuleDefiningSymbol(*I);
if (mp) {
+ // The symbol exists, insert the ModuleProvider into our result,
+ // duplicates wil be ignored
result.insert(mp);
+
+ // Remove the symbol now that its been resolved, being careful to
+ // not invalidate our iterator.
+ std::set<std::string>::iterator save = I;
+ ++I;
+ symbols.erase(save);
+ } else {
+ ++I;
}
}
}
diff --git a/lib/Bytecode/Archive/ArchiveReader.cpp b/lib/Bytecode/Archive/ArchiveReader.cpp
index 615df2bf5f..6f5b9d36ed 100644
--- a/lib/Bytecode/Archive/ArchiveReader.cpp
+++ b/lib/Bytecode/Archive/ArchiveReader.cpp
@@ -407,7 +407,7 @@ Archive::findModuleDefiningSymbol(const std::string& symbol) {
// Look up multiple symbols in the symbol table and return a set of
// ModuleProviders that define those symbols.
void
-Archive::findModulesDefiningSymbols(const std::set<std::string>& symbols,
+Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
std::set<ModuleProvider*>& result)
{
assert(mapfile && base && "Can't findModulesDefiningSymbols on new archive");
@@ -462,11 +462,22 @@ Archive::findModulesDefiningSymbols(const std::set<std::string>& symbols,
// At this point we have a valid symbol table (one way or another) so we
// just use it to quickly find the symbols requested.
- for (std::set<std::string>::const_iterator I=symbols.begin(),
- E=symbols.end(); I != E; ++I) {
+ for (std::set<std::string>::iterator I=symbols.begin(),
+ E=symbols.end(); I != E;) {
+ // See if this symbol exists
ModuleProvider* mp = findModuleDefiningSymbol(*I);
if (mp) {
+ // The symbol exists, insert the ModuleProvider into our result,
+ // duplicates wil be ignored
result.insert(mp);
+
+ // Remove the symbol now that its been resolved, being careful to
+ // not invalidate our iterator.
+ std::set<std::string>::iterator save = I;
+ ++I;
+ symbols.erase(save);
+ } else {
+ ++I;
}
}
}