@@ -631,11 +631,19 @@ class LineJoiner {
631631 unsigned Limit) {
632632 if (Limit == 0 )
633633 return 0 ;
634- if (I[1 ]->InPPDirective != (*I)->InPPDirective ||
635- (I[1 ]->InPPDirective && I[1 ]->First ->HasUnescapedNewline )) {
634+ assert (I[1 ]);
635+ const auto &L1 = *I[1 ];
636+ if (L1.InPPDirective != (*I)->InPPDirective ||
637+ (L1.InPPDirective && L1.First ->HasUnescapedNewline )) {
636638 return 0 ;
637639 }
638- if (I + 2 == E || I[2 ]->Type == LT_Invalid)
640+
641+ if (std::distance (I, E) <= 2 )
642+ return 0 ;
643+
644+ assert (I[2 ]);
645+ const auto &L2 = *I[2 ];
646+ if (L2.Type == LT_Invalid)
639647 return 0 ;
640648
641649 Limit = limitConsideringMacros (I + 1 , E, Limit);
@@ -645,13 +653,13 @@ class LineJoiner {
645653
646654 // Check if it's a namespace inside a namespace, and call recursively if so.
647655 // '3' is the sizes of the whitespace and closing brace for " _inner_ }".
648- if (I[ 1 ]-> First ->is (tok::kw_namespace)) {
649- if (I[ 1 ]-> Last ->is (tok::comment) || !Style.CompactNamespaces )
656+ if (L1. First ->is (tok::kw_namespace)) {
657+ if (L1. Last ->is (tok::comment) || !Style.CompactNamespaces )
650658 return 0 ;
651659
652- assert (Limit >= I[ 1 ]-> Last ->TotalLength + 3 );
653- const unsigned InnerLimit = Limit - I[ 1 ]-> Last ->TotalLength - 3 ;
654- const unsigned MergedLines = tryMergeNamespace (I + 1 , E, InnerLimit);
660+ assert (Limit >= L1. Last ->TotalLength + 3 );
661+ const auto InnerLimit = Limit - L1. Last ->TotalLength - 3 ;
662+ const auto MergedLines = tryMergeNamespace (I + 1 , E, InnerLimit);
655663 if (MergedLines == 0 )
656664 return 0 ;
657665 const auto N = MergedLines + 2 ;
@@ -672,11 +680,11 @@ class LineJoiner {
672680 // line.
673681
674682 // The line which is in the namespace should end with semicolon.
675- if (I[ 1 ]-> Last ->isNot (tok::semi))
683+ if (L1. Last ->isNot (tok::semi))
676684 return 0 ;
677685
678686 // Last, check that the third line starts with a closing brace.
679- if (I[ 2 ]-> First ->isNot (tok::r_brace) || I[ 2 ]-> First ->MustBreakBefore )
687+ if (L2. First ->isNot (tok::r_brace) || L2. First ->MustBreakBefore )
680688 return 0 ;
681689
682690 // If so, merge all three lines.
@@ -987,7 +995,7 @@ class LineJoiner {
987995 SmallVectorImpl<AnnotatedLine *>::const_iterator E,
988996 unsigned Limit) {
989997 unsigned JoinedLength = 0 ;
990- for (auto J = I + 1 ; J != E; ++J) {
998+ for (const auto * J = I + 1 ; J != E; ++J) {
991999 if ((*J)->First ->MustBreakBefore )
9921000 return false ;
9931001
0 commit comments