diff options
author | pennae <github@quasiparticle.net> | 2022-02-04 07:36:56 +0100 |
---|---|---|
committer | pennae <github@quasiparticle.net> | 2022-02-04 15:27:59 +0100 |
commit | 1daf1babf956cab98857db92de8829a1e7f2ae3e (patch) | |
tree | 719be8f62520bff68378037c84aa17c0862f32ac /src | |
parent | fcb33440b6d3038e6761e546fc9434fa8e9a1666 (diff) |
fix nix repl not overriding existing bindings in :a
previously :a would override old bindings of a name with new values if the added
set contained names that were already bound. in nix 2.6 this doesn't happen any
more, which is potentially confusing.
fixes #6041
Diffstat (limited to 'src')
-rw-r--r-- | src/libexpr/nixexpr.hh | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index 4e923ac89..6f6acb074 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -367,15 +367,19 @@ struct StaticEnv void sort() { - std::sort(vars.begin(), vars.end(), + std::stable_sort(vars.begin(), vars.end(), [](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()); + auto it = vars.begin(), jt = it, end = vars.end(); + while (jt != end) { + *it = *jt++; + while (jt != end && it->first == jt->first) *it = *jt++; + it++; + } + vars.erase(it, end); } Vars::const_iterator find(const Symbol & name) const |