Skip to content

fix #2673: avoid visiting the same crate twice #4668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 29, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions src/rt/rust_crate_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

#include "rust_crate_map.h"
#include <set>

void iter_module_map(const mod_entry* map,
void (*fn)(const mod_entry* entry, void *cookie),
Expand All @@ -20,18 +21,27 @@ void iter_module_map(const mod_entry* map,

void iter_crate_map(const cratemap* map,
void (*fn)(const mod_entry* map, void *cookie),
void *cookie) {
// First iterate this crate
iter_module_map(map->entries(), fn, cookie);
// Then recurse on linked crates
// FIXME (#2673) this does double work in diamond-shaped deps. could
// keep a set of visited addresses, if it turns out to be actually
// slow
for (cratemap::iterator i = map->begin(), e = map->end(); i != e; ++i) {
iter_crate_map(*i, fn, cookie);
void *cookie,
std::set<const cratemap*>& visited) {
if (visited.find(map) == visited.end()) {
// Mark this crate visited
visited.insert(map);
// First iterate this crate
iter_module_map(map->entries(), fn, cookie);
// Then recurse on linked crates
for (cratemap::iterator i = map->begin(),
e = map->end(); i != e; ++i) {
iter_crate_map(*i, fn, cookie, visited);
}
}
}

void iter_crate_map(const cratemap* map,
void (*fn)(const mod_entry* map, void *cookie),
void *cookie) {
std::set<const cratemap*> visited;
iter_crate_map(map, fn, cookie, visited);
}
//
// Local Variables:
// mode: C++
Expand Down