mirror of
https://github.com/NixOS/nix.git
synced 2025-12-22 08:51:08 +01:00
Use transparent comparators for std::set<std::string> (NFC)
This patch finally applies the transition to std::less<>,
which is a transparent comparator. There's no functional
change and string lookups in sets are now more efficient
and don't produce temporaries (e.g. set.find(std::string_view{"key"})).
This commit is contained in:
parent
5278cd2396
commit
ebb836d499
12 changed files with 66 additions and 40 deletions
|
|
@ -5,13 +5,13 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
template<typename T>
|
||||
std::vector<T> topoSort(std::set<T> items,
|
||||
std::function<std::set<T>(const T &)> getChildren,
|
||||
template<typename T, typename Compare>
|
||||
std::vector<T> topoSort(std::set<T, Compare> items,
|
||||
std::function<std::set<T, Compare>(const T &)> getChildren,
|
||||
std::function<Error(const T &, const T &)> makeCycleError)
|
||||
{
|
||||
std::vector<T> sorted;
|
||||
std::set<T> visited, parents;
|
||||
decltype(items) visited, parents;
|
||||
|
||||
std::function<void(const T & path, const T * parent)> dfsVisit;
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ std::vector<T> topoSort(std::set<T> items,
|
|||
if (!visited.insert(path).second) return;
|
||||
parents.insert(path);
|
||||
|
||||
std::set<T> references = getChildren(path);
|
||||
auto references = getChildren(path);
|
||||
|
||||
for (auto & i : references)
|
||||
/* Don't traverse into items that don't exist in our starting set. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue