From 8235ae6999b4fe148805651bd7be6ee667cbb8c2 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 5 Aug 2023 12:19:35 +0100 Subject: Refactor JsonSerializer::ModelTreeIterate with no pointer copy --- slicer/json/serializer.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/slicer/json/serializer.cpp b/slicer/json/serializer.cpp index 227f3c9..0c993c4 100644 --- a/slicer/json/serializer.cpp +++ b/slicer/json/serializer.cpp @@ -267,17 +267,20 @@ namespace Slicer { } case ModelPartType::Complex: if (mp->HasValue()) { - json::Object nn; + auto oec = [n, &name](const auto & lmp) { + auto & obj = std::get(*n).emplace(name, json::Object {}).first->second; + lmp->OnEachChild([&obj](auto && PH1, auto && PH2, auto &&) { + return JsonSerializer::ModelTreeIterate(&obj, PH1, PH2); + }); + return &std::get(obj); + }; if (auto typeIdName = mp->GetTypeIdProperty()) { if (auto typeId = mp->GetTypeId()) { - nn.insert({*typeIdName, *typeId}); - mp = mp->GetSubclassModelPart(*typeId); + oec(mp->GetSubclassModelPart(*typeId))->emplace(*typeIdName, *typeId); + return; } } - mp->OnEachChild([capture0 = &std::get(*n).insert({name, nn}).first->second]( - auto && PH1, auto && PH2, auto &&) { - return JsonSerializer::ModelTreeIterate(capture0, PH1, PH2); - }); + oec(mp); } break; case ModelPartType::Sequence: -- cgit v1.2.3