mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-27 19:46:40 +03:00
Remove list sorting
This commit is contained in:
parent
36c00c1080
commit
e1ecc2b6c1
1 changed files with 1 additions and 36 deletions
|
@ -1,6 +1,5 @@
|
||||||
#include <nix/config.h> // for nix/globals.hh's reference to SYSTEM
|
#include <nix/config.h> // for nix/globals.hh's reference to SYSTEM
|
||||||
|
|
||||||
#include <algorithm> // for sort
|
|
||||||
#include <functional> // for function
|
#include <functional> // for function
|
||||||
#include <iostream> // for operator<<, basic_ostream, ostrin...
|
#include <iostream> // for operator<<, basic_ostream, ostrin...
|
||||||
#include <iterator> // for next
|
#include <iterator> // for next
|
||||||
|
@ -276,7 +275,7 @@ Value parseAndEval(EvalState * state, std::string const & expression, std::strin
|
||||||
|
|
||||||
void printValue(Context * ctx, Out & out, std::variant<Value, Error> maybe_value, std::string const & path);
|
void printValue(Context * ctx, Out & out, std::variant<Value, Error> maybe_value, std::string const & path);
|
||||||
|
|
||||||
void printUnsortedList(Context * ctx, Out & out, Value & v)
|
void printList(Context * ctx, Out & out, Value & v)
|
||||||
{
|
{
|
||||||
Out list_out(out, "[", "]", v.listSize());
|
Out list_out(out, "[", "]", v.listSize());
|
||||||
for (unsigned int n = 0; n < v.listSize(); ++n) {
|
for (unsigned int n = 0; n < v.listSize(); ++n) {
|
||||||
|
@ -285,40 +284,6 @@ void printUnsortedList(Context * ctx, Out & out, Value & v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void printSortedList(Context * ctx, Out & out, Value & v)
|
|
||||||
{
|
|
||||||
std::vector<std::string> results;
|
|
||||||
for (unsigned int n = 0; n < v.listSize(); ++n) {
|
|
||||||
std::ostringstream buf;
|
|
||||||
Out buf_out(buf);
|
|
||||||
printValue(ctx, buf_out, *v.listElems()[n], "");
|
|
||||||
results.push_back(buf.str());
|
|
||||||
}
|
|
||||||
std::sort(results.begin(), results.end());
|
|
||||||
Out list_out(out, "[", "]", v.listSize());
|
|
||||||
for (auto const & v : results) {
|
|
||||||
list_out << v << Out::sep;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool shouldSort(Context * ctx, Value & v)
|
|
||||||
{
|
|
||||||
// Some lists should clearly be printed in sorted order, like
|
|
||||||
// environment.systemPackages. Some clearly should not, like
|
|
||||||
// services.xserver.multitouch.buttonsMap. As a conservative heuristic, sort
|
|
||||||
// lists of derivations.
|
|
||||||
return v.listSize() > 0 && ctx->state->isDerivation(*v.listElems()[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void printList(Context * ctx, Out & out, Value & v)
|
|
||||||
{
|
|
||||||
if (shouldSort(ctx, v)) {
|
|
||||||
printSortedList(ctx, out, v);
|
|
||||||
} else {
|
|
||||||
printUnsortedList(ctx, out, v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void printAttrs(Context * ctx, Out & out, Value & v, std::string const & path)
|
void printAttrs(Context * ctx, Out & out, Value & v, std::string const & path)
|
||||||
{
|
{
|
||||||
Out attrs_out(out, "{", "}", v.attrs->size());
|
Out attrs_out(out, "{", "}", v.attrs->size());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue