@@ -392,28 +392,21 @@ namespace daw {
392392 return ;
393393 }
394394
395- types::ti_object &orig = *pos;
396395 std::vector<std::pair<std::string, types::ti_value>> diff{};
397-
398- static auto const comp = []( auto const &c1, auto const &c2 ) {
399- return c1.first < c2.first ;
400- };
401- std::set_difference ( orig.children .begin ( ), orig.children .end ( ),
402- obj.children .begin ( ), obj.children .end ( ),
403- std::back_inserter ( diff ), comp );
404-
405- for ( auto &child : diff ) {
406- if ( child.second .is_null ( ) ) {
407- if ( !orig.children [child.first ].is_null ( ) ) {
408- orig.children [child.first ] = child.second ;
409- }
410- orig.children [child.first ].is_optional ( ) = true ;
411- } else if ( orig.children [child.first ].is_null ( ) ) {
412- orig.children [child.first ] = child.second ;
413- } /* else {
414- orig.children[child.first] = child.second;
415- }*/
416- orig.children [child.first ].is_optional ( ) = true ;
396+ for ( auto &orig_child : pos->children ) {
397+ auto child_pos = std::find_if (
398+ obj.children .begin ( ), obj.children .end ( ),
399+ [&]( auto const &v ) { return v.first == orig_child.first ; } );
400+ if ( child_pos == obj.children .end ( ) ) {
401+ orig_child.second .is_optional ( ) = true ;
402+ continue ;
403+ }
404+ if ( child_pos->second .is_null ( ) ) {
405+ orig_child.second .is_optional ( ) = true ;
406+ } else if ( orig_child.second .is_null ( ) ) {
407+ orig_child.second = child_pos->second ;
408+ orig_child.second .is_optional ( ) = true ;
409+ }
417410 }
418411 }
419412
@@ -424,10 +417,11 @@ namespace daw {
424417 if ( a.is_null ( ) ) {
425418 result = b;
426419 result.is_optional ( ) = true ;
427- } else if ( b.is_null ( ) ) {
428- result = a;
429- result.is_optional ( ) = true ;
430420 } else {
421+ if ( b.is_null ( ) ) {
422+ result = a;
423+ result.is_optional ( ) = true ;
424+ }
431425 result = a;
432426 result.is_optional ( ) = a.is_optional ( ) or b.is_optional ( );
433427 }
0 commit comments