From 466c90a34ea0c268edb83a0a55576322bdc359ff Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sat, 21 Jan 2017 12:42:53 -0500 Subject: [PATCH] use unordered_map for library symbol table. --- link.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/link.cpp b/link.cpp index ff3ef98..1957532 100644 --- a/link.cpp +++ b/link.cpp @@ -1359,6 +1359,33 @@ enum { kProcessed = 2, }; + +/* + * observation: the library symbol size will far exceed the missing symbols size. + * Therefore, library symbols should be an unordered_map and explicitely look up + * each undefined symbol. + * + * output c is a map (and thus sorted) to guarantee reproducable builds. + * (could use a vector then sort/unique it...) + */ +bool intersection(const std::unordered_map &a, + const std::set &b, + std::map &c) +{ + bool rv = false; + + for (const auto &name : b) { + auto iter = a.find(name); + if (iter == a.end()) continue; + rv = true; + c.emplace(iter->second, kPending); + } + + return rv; +} + + +#if 0 bool intersection(const std::map &a, const std::set &b, std::map &c) @@ -1386,6 +1413,7 @@ bool intersection(const std::map &a, return rv; } +#endif bool one_lib(const std::string &path) { @@ -1452,7 +1480,7 @@ bool one_lib(const std::string &path) { //iter += size; // don't care about the name. } - std::map lib_symbol_map; + std::unordered_map lib_symbol_map; // map of which modules have been loaded or are pending processing.