@@ -90,7 +90,7 @@ int AlreadyFormattedPartitionLength(const TokenPartitionTree& partition) {
9090 width += token.before .spaces_required + token.Length ();
9191 }
9292
93- for (const auto & child : partition.Children ()) {
93+ for (const auto & child : * partition.Children ()) {
9494 CHECK_EQ (child.Value ().PartitionPolicy (), PartitionPolicyEnum::kInline );
9595 if (child.Value ().TokensRange ().begin () != tokens.begin ()) {
9696 const auto & first_token = child.Value ().TokensRange ().front ();
@@ -500,7 +500,7 @@ LayoutFunction TokenPartitionsLayoutOptimizer::CalculateOptimalLayout(
500500
501501 // Traverse and calculate children layouts
502502
503- absl::FixedArray<LayoutFunction> layouts (node.Children (). size ());
503+ absl::FixedArray<LayoutFunction> layouts (node.Children ()-> size ());
504504
505505 switch (node.Value ().PartitionPolicy ()) {
506506 case PartitionPolicyEnum::kJuxtaposition :
@@ -509,7 +509,7 @@ LayoutFunction TokenPartitionsLayoutOptimizer::CalculateOptimalLayout(
509509 case PartitionPolicyEnum::kFitOnLineElseExpand :
510510 case PartitionPolicyEnum::kAppendFittingSubPartitions :
511511 case PartitionPolicyEnum::kJuxtapositionOrIndentedStack : {
512- std::transform (node.Children (). begin (), node.Children (). end (),
512+ std::transform (node.Children ()-> begin (), node.Children ()-> end (),
513513 layouts.begin (), [=](const TokenPartitionTree& n) {
514514 return this ->CalculateOptimalLayout (n);
515515 });
@@ -520,7 +520,7 @@ LayoutFunction TokenPartitionsLayoutOptimizer::CalculateOptimalLayout(
520520 case PartitionPolicyEnum::kAlwaysExpand :
521521 case PartitionPolicyEnum::kTabularAlignment : {
522522 const int indentation = node.Value ().IndentationSpaces ();
523- std::transform (node.Children (). begin (), node.Children (). end (),
523+ std::transform (node.Children ()-> begin (), node.Children ()-> end (),
524524 layouts.begin (), [=](const TokenPartitionTree& n) {
525525 const int relative_indentation =
526526 n.Value ().IndentationSpaces () - indentation;
@@ -558,10 +558,11 @@ LayoutFunction TokenPartitionsLayoutOptimizer::CalculateOptimalLayout(
558558 case PartitionPolicyEnum::kStack :
559559 return factory_.Stack (layouts.begin (), layouts.end ());
560560 case PartitionPolicyEnum::kWrap : {
561- if (VLOG_IS_ON (0 ) && node.Children ().size () > 2 ) {
562- const int indentation = node.Children ()[1 ].Value ().IndentationSpaces ();
563- for (const auto & child : iterator_range (node.Children ().begin () + 2 ,
564- node.Children ().end ())) {
561+ if (VLOG_IS_ON (0 ) && node.Children ()->size () > 2 ) {
562+ const int indentation =
563+ node.Children ()->at (1 ).Value ().IndentationSpaces ();
564+ for (const auto & child : iterator_range (node.Children ()->begin () + 2 ,
565+ node.Children ()->end ())) {
565566 if (child.Value ().IndentationSpaces () != indentation) {
566567 VLOG (0 ) << " Indentations of subpartitions from the second to the "
567568 " last are not equal. Using indentation of the second "
@@ -571,8 +572,8 @@ LayoutFunction TokenPartitionsLayoutOptimizer::CalculateOptimalLayout(
571572 }
572573 }
573574 const int hanging_indentation =
574- (node.Children (). size () > 1 )
575- ? (node.Children ()[ 1 ] .Value ().IndentationSpaces () -
575+ (node.Children ()-> size () > 1 )
576+ ? (node.Children ()-> at ( 1 ) .Value ().IndentationSpaces () -
576577 node.Value ().IndentationSpaces ())
577578 : 0 ;
578579
@@ -592,7 +593,7 @@ LayoutFunction TokenPartitionsLayoutOptimizer::CalculateOptimalLayout(
592593 const int indentation = node.Value ().IndentationSpaces ();
593594 for (size_t i = 0 ; i < layouts.size (); ++i) {
594595 const int relative_indentation =
595- node.Children ()[i] .Value ().IndentationSpaces () - indentation;
596+ node.Children ()-> at (i) .Value ().IndentationSpaces () - indentation;
596597 layouts[i] = factory_.Indent (layouts[i], relative_indentation);
597598 }
598599 auto stack = factory_.Stack (layouts.begin (), layouts.end ());
@@ -615,7 +616,7 @@ LayoutFunction TokenPartitionsLayoutOptimizer::CalculateOptimalLayout(
615616 // When not a leaf, it contains partitions with kInline
616617 // policy. Pack them horizontally.
617618 const bool all_children_are_inlines =
618- std::all_of (node.Children (). begin (), node.Children (). end (),
619+ std::all_of (node.Children ()-> begin (), node.Children ()-> end (),
619620 [](const TokenPartitionTree& child) {
620621 return child.Value ().PartitionPolicy () ==
621622 PartitionPolicyEnum::kInline ;
@@ -631,7 +632,7 @@ LayoutFunction TokenPartitionsLayoutOptimizer::CalculateOptimalLayout(
631632 // Preserve spacing of the first sublayout. This has to be done because
632633 // the first layout in a line uses IndentationSpaces instead of
633634 // SpacesBefore.
634- const auto indent = node.Children (). front ().Value ().IndentationSpaces ();
635+ const auto indent = node.Children ()-> front ().Value ().IndentationSpaces ();
635636 layouts.front () = factory_.Indent (layouts.front (), indent);
636637
637638 return factory_.Juxtaposition (layouts.begin (), layouts.end ());
@@ -679,26 +680,26 @@ void TreeReconstructor::TraverseTree(const LayoutTree& layout_tree) {
679680 layout.TokensRange ().begin (),
680681 PartitionPolicyEnum::kAlreadyFormatted );
681682 uwline.SpanUpToToken (layout.TokensRange ().end ());
682- tree_.Children (). emplace_back (uwline);
683- current_node_ = &tree_.Children (). back ();
683+ tree_.Children ()-> emplace_back (uwline);
684+ current_node_ = &tree_.Children ()-> back ();
684685 } else {
685686 const auto tokens = layout.TokensRange ();
686687 CHECK (current_node_->Value ().TokensRange ().end () == tokens.begin ());
687688
688689 current_node_->Value ().SpanUpToToken (tokens.end ());
689690
690- auto & slices = current_node_->Children ();
691+ auto & slices = * current_node_->Children ();
691692 // TODO(mglb): add support for break_decision == Preserve
692693 if (layout.SpacesBefore () == tokens.front ().before .spaces_required ) {
693694 // No need for separate inline partition
694- if (!slices. empty ( ))
695+ if (!is_leaf (*current_node_ ))
695696 slices.back ().Value ().SpanUpToToken (tokens.end ());
696697 return ;
697698 }
698699
699700 // Wrap previous tokens in the line
700- if (slices. empty ( )) {
701- current_node_->Children (). emplace_back (
701+ if (is_leaf (*current_node_ )) {
702+ current_node_->Children ()-> emplace_back (
702703 UnwrappedLine (0 , current_node_->Value ().TokensRange ().begin (),
703704 PartitionPolicyEnum::kInline ));
704705 }
@@ -708,7 +709,7 @@ void TreeReconstructor::TraverseTree(const LayoutTree& layout_tree) {
708709 auto slice = UnwrappedLine (layout.SpacesBefore (), tokens.begin (),
709710 PartitionPolicyEnum::kInline );
710711 slice.SpanUpToToken (tokens.end ());
711- current_node_->Children (). emplace_back (slice);
712+ current_node_->Children ()-> emplace_back (slice);
712713 }
713714 return ;
714715 }
@@ -756,20 +757,19 @@ void TreeReconstructor::TraverseTree(const LayoutTree& layout_tree) {
756757void TreeReconstructor::ReplaceTokenPartitionTreeNode (
757758 TokenPartitionTree* node) {
758759 CHECK_NOTNULL (node);
759- CHECK (!tree_. Children (). empty ( ));
760+ CHECK (!is_leaf (tree_ ));
760761
761- if (tree_.Children (). size () == 1 ) {
762- *node = std::move (tree_.Children (). front ());
762+ if (tree_.Children ()-> size () == 1 ) {
763+ *node = std::move (tree_.Children ()-> front ());
763764 } else {
764- const auto & first_line = tree_.Children (). front ().Value ();
765- const auto & last_line = tree_.Children (). back ().Value ();
765+ const auto & first_line = tree_.Children ()-> front ().Value ();
766+ const auto & last_line = tree_.Children ()-> back ().Value ();
766767
767- node-> Value () = UnwrappedLine (current_indentation_spaces_,
768+ tree_. Value () = UnwrappedLine (current_indentation_spaces_,
768769 first_line.TokensRange ().begin (),
769770 PartitionPolicyEnum::kAlwaysExpand );
770- node->Value ().SpanUpToToken (last_line.TokensRange ().end ());
771- node->Children ().clear ();
772- AdoptSubtreesFrom (*node, &tree_);
771+ tree_.Value ().SpanUpToToken (last_line.TokensRange ().end ());
772+ *node = std::move (tree_);
773773 }
774774}
775775
0 commit comments