mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 12:06:01 +01:00
libexpr: Use recursive lambda instead of std::function
There's no reason to use a std::function for recursive lambdas since there are polymorphic lambdas.
This commit is contained in:
parent
df4e55ffc1
commit
a80a5c4dba
1 changed files with 4 additions and 6 deletions
|
|
@ -13,9 +13,7 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value ** args, Va
|
||||||
|
|
||||||
std::istringstream tomlStream(std::string{toml});
|
std::istringstream tomlStream(std::string{toml});
|
||||||
|
|
||||||
std::function<void(Value &, toml::value)> visit;
|
auto visit = [&](auto & self, Value & v, toml::value t) -> void {
|
||||||
|
|
||||||
visit = [&](Value & v, toml::value t) {
|
|
||||||
switch (t.type()) {
|
switch (t.type()) {
|
||||||
case toml::value_t::table: {
|
case toml::value_t::table: {
|
||||||
auto table = toml::get<toml::table>(t);
|
auto table = toml::get<toml::table>(t);
|
||||||
|
|
@ -30,7 +28,7 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value ** args, Va
|
||||||
|
|
||||||
for (auto & elem : table) {
|
for (auto & elem : table) {
|
||||||
forceNoNullByte(elem.first);
|
forceNoNullByte(elem.first);
|
||||||
visit(attrs.alloc(elem.first), elem.second);
|
self(self, attrs.alloc(elem.first), elem.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
v.mkAttrs(attrs);
|
v.mkAttrs(attrs);
|
||||||
|
|
@ -40,7 +38,7 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value ** args, Va
|
||||||
|
|
||||||
auto list = state.buildList(array.size());
|
auto list = state.buildList(array.size());
|
||||||
for (const auto & [n, v] : enumerate(list))
|
for (const auto & [n, v] : enumerate(list))
|
||||||
visit(*(v = state.allocValue()), array[n]);
|
self(self, *(v = state.allocValue()), array[n]);
|
||||||
v.mkList(list);
|
v.mkList(list);
|
||||||
} break;
|
} break;
|
||||||
case toml::value_t::boolean:
|
case toml::value_t::boolean:
|
||||||
|
|
@ -81,7 +79,7 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value ** args, Va
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
visit(val, toml::parse(tomlStream, "fromTOML" /* the "filename" */));
|
visit(visit, val, toml::parse(tomlStream, "fromTOML" /* the "filename" */));
|
||||||
} catch (std::exception & e) { // TODO: toml::syntax_error
|
} catch (std::exception & e) { // TODO: toml::syntax_error
|
||||||
state.error<EvalError>("while parsing TOML: %s", e.what()).atPos(pos).debugThrow();
|
state.error<EvalError>("while parsing TOML: %s", e.what()).atPos(pos).debugThrow();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue