@@ -139,6 +139,9 @@ struct ContainerHandle {
139139
140140 /* implicit*/ ContainerHandle(container_type* c) : handle(c) {}
141141
142+ /* implicit*/ ContainerHandle(std::unique_ptr<container_type> c)
143+ : handle(std::move(c)) {}
144+
142145 void set_leaf (leaf_type* leaf) {
143146 pytree_assert (handle->kind == Kind::Leaf);
144147 handle->leaf = leaf;
@@ -486,10 +489,10 @@ TreeSpec<Aux> from_str_internal(
486489 read_idx++;
487490 auto layout = read_node_layout (spec, read_idx);
488491 const auto size = layout.size ();
489- auto c = new TreeSpecContainer<Aux>(kind, size);
492+ auto c = std::make_unique< TreeSpecContainer<Aux> >(kind, size);
490493
491494 if (Kind::Custom == kind) {
492- c->custom_type = custom_type;
495+ c->custom_type = std::move ( custom_type) ;
493496 }
494497
495498 size_t child_idx = 0 ;
@@ -509,14 +512,14 @@ TreeSpec<Aux> from_str_internal(
509512 read_idx++;
510513 }
511514 c->leaves_num = leaves_offset;
512- return c ;
515+ return TreeSpec<Aux>( std::move (c)) ;
513516 }
514517
515518 case Config::kDict : {
516519 read_idx++;
517520 auto layout = read_node_layout (spec, read_idx);
518521 const auto size = layout.size ();
519- auto c = new TreeSpecContainer<Aux>(Kind::Dict, size);
522+ auto c = std::make_unique< TreeSpecContainer<Aux> >(Kind::Dict, size);
520523
521524 size_t child_idx = 0 ;
522525 size_t leaves_offset = 0 ;
@@ -549,7 +552,7 @@ TreeSpec<Aux> from_str_internal(
549552 read_idx++;
550553 }
551554 c->leaves_num = leaves_offset;
552- return c ;
555+ return TreeSpec<Aux>( std::move (c)) ;
553556 }
554557
555558 case Config::kLeaf :
0 commit comments