From b3f01efdec0a74dc353e14ce278e9bdabb51793f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 5 Aug 2023 12:33:31 +0100 Subject: Refactor JsonSerializer::ModelTreeIterateRoot with no pointer copy --- slicer/json/serializer.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/slicer/json/serializer.cpp b/slicer/json/serializer.cpp index 0c993c4..728d174 100644 --- a/slicer/json/serializer.cpp +++ b/slicer/json/serializer.cpp @@ -324,18 +324,23 @@ namespace Slicer { case ModelPartType::Simple: mp->GetValue(JsonValueTarget(*n)); break; - case ModelPartType::Complex: - *n = json::Object(); + case ModelPartType::Complex: { + auto oec = [n](const auto & lmp) { + *n = json::Object(); + lmp->OnEachChild([n](auto && PH1, auto && PH2, auto &&) { + return JsonSerializer::ModelTreeIterate(n, PH1, PH2); + }); + return &std::get(*n); + }; if (auto typeIdName = mp->GetTypeIdProperty()) { if (auto typeId = mp->GetTypeId()) { - std::get(*n).insert({*typeIdName, *typeId}); - mp = mp->GetSubclassModelPart(*typeId); + oec(mp->GetSubclassModelPart(*typeId))->emplace(*typeIdName, *typeId); + return; } } - mp->OnEachChild([n](auto && PH1, auto && PH2, auto &&) { - return JsonSerializer::ModelTreeIterate(n, PH1, PH2); - }); + oec(mp); break; + } case ModelPartType::Sequence: *n = json::Array(); mp->OnEachChild([n](auto &&, auto && PH2, auto &&) { -- cgit v1.2.3