1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 03:56: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.

(cherry picked from commit a80a5c4dba)
This commit is contained in:
Sergei Zimmerman 2025-08-12 14:54:53 +03:00
parent 05c7da24cc
commit 1b8acb5694
No known key found for this signature in database

View file

@ -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();
} }