[PATCH] Store first and last newline position in the token text for string literals and comments.

Alexander Kornienko alexfh at google.com
Fri Aug 30 07:32:13 PDT 2013



================
Comment at: lib/Format/ContinuationIndenter.cpp:596
@@ -599,2 +595,3 @@
 
+  StringRef FirstLine = Current.TokenText.substr(0, Current.FirstNewlineInText);
   unsigned ColumnsUsed =
----------------
Manuel Klimek wrote:
> Daniel Jasper wrote:
> > We never use FirstNewlineInText or LastNewlineInText for anything other than getting the substring and then calculating the CodePointCount. Getting the CodePointCount again is a linear operation that we do repeatedly while finding the best layout. How about precomputing the CodePointCount for both values instead.
> +1, I also find it more intuitive to have the first and last-line length in the token.
> 
Totally makes sense, as getCodePointCount is even slower (though, also linear) than find.

================
Comment at: lib/Format/ContinuationIndenter.cpp:599
@@ -603,2 +598,3 @@
+      StartColumn + encoding::getCodePointCount(FirstLine, Encoding);
   if (ColumnsUsed > getColumnLimit())
     return Style.PenaltyExcessCharacter * (ColumnsUsed - getColumnLimit());
----------------
Manuel Klimek wrote:
> While we're at it - don't we want to take the excess characters of the middle lines into account? Otherwise, won't we introduce indent levels that push the middle lines over the limit without noticing?
No, we can't affect layout of parts of string literals after an escaped newline.


http://llvm-reviews.chandlerc.com/D1556



More information about the cfe-commits mailing list