Skip to content

Commit 3bf71fc

Browse files
xokdviummergify[bot]
authored andcommitted
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 a80a5c4)
1 parent 4405500 commit 3bf71fc

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/libexpr/primops/fromTOML.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value ** args, Va
1313

1414
std::istringstream tomlStream(std::string{toml});
1515

16-
std::function<void(Value &, toml::value)> visit;
17-
18-
visit = [&](Value & v, toml::value t) {
16+
auto visit = [&](auto & self, Value & v, toml::value t) -> void {
1917
switch (t.type()) {
2018
case toml::value_t::table: {
2119
auto table = toml::get<toml::table>(t);
@@ -30,7 +28,7 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value ** args, Va
3028

3129
for (auto & elem : table) {
3230
forceNoNullByte(elem.first);
33-
visit(attrs.alloc(elem.first), elem.second);
31+
self(self, attrs.alloc(elem.first), elem.second);
3432
}
3533

3634
v.mkAttrs(attrs);
@@ -40,7 +38,7 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value ** args, Va
4038

4139
auto list = state.buildList(array.size());
4240
for (const auto & [n, v] : enumerate(list))
43-
visit(*(v = state.allocValue()), array[n]);
41+
self(self, *(v = state.allocValue()), array[n]);
4442
v.mkList(list);
4543
} break;
4644
case toml::value_t::boolean:
@@ -81,7 +79,7 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value ** args, Va
8179
};
8280

8381
try {
84-
visit(val, toml::parse(tomlStream, "fromTOML" /* the "filename" */));
82+
visit(visit, val, toml::parse(tomlStream, "fromTOML" /* the "filename" */));
8583
} catch (std::exception & e) { // TODO: toml::syntax_error
8684
state.error<EvalError>("while parsing TOML: %s", e.what()).atPos(pos).debugThrow();
8785
}

0 commit comments

Comments
 (0)