@@ -139,6 +139,9 @@ struct ContainerHandle {
139
139
140
140
/* implicit*/ ContainerHandle(container_type* c) : handle(c) {}
141
141
142
+ /* implicit*/ ContainerHandle(std::unique_ptr<container_type> c)
143
+ : handle(std::move(c)) {}
144
+
142
145
void set_leaf (leaf_type* leaf) {
143
146
pytree_assert (handle->kind == Kind::Leaf);
144
147
handle->leaf = leaf;
@@ -486,10 +489,10 @@ TreeSpec<Aux> from_str_internal(
486
489
read_idx++;
487
490
auto layout = read_node_layout (spec, read_idx);
488
491
const auto size = layout.size ();
489
- auto c = new TreeSpecContainer<Aux>(kind, size);
492
+ auto c = std::make_unique< TreeSpecContainer<Aux> >(kind, size);
490
493
491
494
if (Kind::Custom == kind) {
492
- c->custom_type = custom_type;
495
+ c->custom_type = std::move ( custom_type) ;
493
496
}
494
497
495
498
size_t child_idx = 0 ;
@@ -509,14 +512,14 @@ TreeSpec<Aux> from_str_internal(
509
512
read_idx++;
510
513
}
511
514
c->leaves_num = leaves_offset;
512
- return c ;
515
+ return TreeSpec<Aux>( std::move (c)) ;
513
516
}
514
517
515
518
case Config::kDict : {
516
519
read_idx++;
517
520
auto layout = read_node_layout (spec, read_idx);
518
521
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);
520
523
521
524
size_t child_idx = 0 ;
522
525
size_t leaves_offset = 0 ;
@@ -549,7 +552,7 @@ TreeSpec<Aux> from_str_internal(
549
552
read_idx++;
550
553
}
551
554
c->leaves_num = leaves_offset;
552
- return c ;
555
+ return TreeSpec<Aux>( std::move (c)) ;
553
556
}
554
557
555
558
case Config::kLeaf :
0 commit comments