From a80a5c4dba0d944fab8f5ed57a343869ae96bf16 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Tue, 12 Aug 2025 14:54:53 +0300 Subject: [PATCH] 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. --- src/libexpr/primops/fromTOML.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/libexpr/primops/fromTOML.cc b/src/libexpr/primops/fromTOML.cc index 18a988d67..9ade6705e 100644 --- a/src/libexpr/primops/fromTOML.cc +++ b/src/libexpr/primops/fromTOML.cc @@ -13,9 +13,7 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value ** args, Va std::istringstream tomlStream(std::string{toml}); - std::function visit; - - visit = [&](Value & v, toml::value t) { + auto visit = [&](auto & self, Value & v, toml::value t) -> void { switch (t.type()) { case toml::value_t::table: { auto table = toml::get(t); @@ -30,7 +28,7 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value ** args, Va for (auto & elem : table) { forceNoNullByte(elem.first); - visit(attrs.alloc(elem.first), elem.second); + self(self, attrs.alloc(elem.first), elem.second); } 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()); for (const auto & [n, v] : enumerate(list)) - visit(*(v = state.allocValue()), array[n]); + self(self, *(v = state.allocValue()), array[n]); v.mkList(list); } break; case toml::value_t::boolean: @@ -81,7 +79,7 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value ** args, Va }; 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 state.error("while parsing TOML: %s", e.what()).atPos(pos).debugThrow(); }