summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/ContinuationIndenter.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2013-09-02 13:58:14 +0000
committerAlexander Kornienko <alexfh@google.com>2013-09-02 13:58:14 +0000
commit632abb9b21e0bb847d26c404f9c0b0dadf9ed0da (patch)
tree98ffa7127d3dedec3b6b1a1bf1500ee9c5192960 /clang/lib/Format/ContinuationIndenter.cpp
parent9acf3dbf1da0a109376be2553ad5b36b420fadc9 (diff)
downloadbcm5719-llvm-632abb9b21e0bb847d26c404f9c0b0dadf9ed0da.tar.gz
bcm5719-llvm-632abb9b21e0bb847d26c404f9c0b0dadf9ed0da.zip
Store first and last newline position in the token text for string literals and comments.
Summary: Store first and last newline position in the token text for string literals and comments to avoid doing .find('\n') for each possible solution. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1556 llvm-svn: 189758
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp31
1 files changed, 9 insertions, 22 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 878580e8920..9891cb2e09c 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -583,23 +583,16 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
unsigned
ContinuationIndenter::addMultilineStringLiteral(const FormatToken &Current,
LineState &State) {
- StringRef Text = Current.TokenText;
- // We can only affect layout of the first and the last line, so the penalty
- // for all other lines is constant, and we ignore it.
- size_t FirstLineBreak = Text.find('\n');
- size_t LastLineBreak = Text.find_last_of('\n');
- assert(FirstLineBreak != StringRef::npos);
- unsigned StartColumn = State.Column - Current.CodePointCount;
- State.Column =
- encoding::getCodePointCount(Text.substr(LastLineBreak + 1), Encoding);
-
// Break before further function parameters on all levels.
for (unsigned i = 0, e = State.Stack.size(); i != e; ++i)
State.Stack[i].BreakBeforeParameter = true;
unsigned ColumnsUsed =
- StartColumn +
- encoding::getCodePointCount(Text.substr(0, FirstLineBreak), Encoding);
+ State.Column - Current.CodePointCount + Current.CodePointsInFirstLine;
+ // We can only affect layout of the first and the last line, so the penalty
+ // for all other lines is constant, and we ignore it.
+ State.Column = Current.CodePointsInLastLine;
+
if (ColumnsUsed > getColumnLimit())
return Style.PenaltyExcessCharacter * (ColumnsUsed - getColumnLimit());
return 0;
@@ -619,7 +612,7 @@ unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current,
// Don't break string literals with (in case of non-raw strings, escaped)
// newlines. As clang-format must not change the string's content, it is
// unlikely that we'll end up with a better format.
- if (Current.IsMultiline)
+ if (Current.isMultiline())
return addMultilineStringLiteral(Current, State);
// Only break up default narrow strings.
@@ -649,14 +642,8 @@ unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current,
// FIXME: If we want to handle them correctly, we'll need to adjust
// leading whitespace in consecutive lines when changing indentation of
// the first line similar to what we do with block comments.
- if (Current.IsMultiline) {
- StringRef::size_type EscapedNewlinePos = Current.TokenText.find("\\\n");
- assert(EscapedNewlinePos != StringRef::npos);
- State.Column =
- StartColumn +
- encoding::getCodePointCount(
- Current.TokenText.substr(0, EscapedNewlinePos), Encoding) +
- 1;
+ if (Current.isMultiline()) {
+ State.Column = StartColumn + Current.CodePointsInFirstLine;
return 0;
}
@@ -740,7 +727,7 @@ bool ContinuationIndenter::NextIsMultilineString(const LineState &State) {
// AlwaysBreakBeforeMultilineStrings implementation.
if (Current.TokenText.startswith("R\""))
return false;
- if (Current.IsMultiline)
+ if (Current.isMultiline())
return true;
if (Current.getNextNonComment() &&
Current.getNextNonComment()->is(tok::string_literal))
OpenPOWER on IntegriCloud