1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 23:11:16 +02:00

Fix accidental O(n^2 * log n) performance in NixRepl::addAttrsToScope

Only sort once, after adding all of the attrs first. This reduces my
`nix repl '<nixpkgs>'` loading time from 1.07s to 103ms.

Fixes #5823
This commit is contained in:
Yorick van Pelt 2021-12-27 13:18:55 +01:00
parent af553b2090
commit a4ab0a74d9
No known key found for this signature in database
GPG key ID: D8D3CC6D951384DE
2 changed files with 17 additions and 2 deletions

View file

@ -368,6 +368,13 @@ struct StaticEnv
[](const Vars::value_type & a, const Vars::value_type & b) { return a.first < b.first; });
}
void deduplicate()
{
const auto last = std::unique(vars.begin(), vars.end(),
[] (const Vars::value_type & a, const Vars::value_type & b) { return a.first == b.first; });
vars.erase(last, vars.end());
}
Vars::const_iterator find(const Symbol & name) const
{
Vars::value_type key(name, 0);