summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.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/Format.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/Format.cpp')
-rw-r--r--clang/lib/Format/Format.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 84bf36c7fd2..39d2c0f96c3 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -596,10 +596,16 @@ private:
FormatTok->CodePointCount =
encoding::getCodePointCount(FormatTok->TokenText, Encoding);
- if (FormatTok->isOneOf(tok::string_literal, tok::comment) &&
- FormatTok->TokenText.find('\n') != StringRef::npos)
- FormatTok->IsMultiline = true;
-
+ if (FormatTok->isOneOf(tok::string_literal, tok::comment)) {
+ StringRef Text = FormatTok->TokenText;
+ size_t FirstNewlinePos = Text.find('\n');
+ if (FirstNewlinePos != StringRef::npos) {
+ FormatTok->CodePointsInFirstLine = encoding::getCodePointCount(
+ Text.substr(0, FirstNewlinePos), Encoding);
+ FormatTok->CodePointsInLastLine = encoding::getCodePointCount(
+ Text.substr(Text.find_last_of('\n') + 1), Encoding);
+ }
+ }
// FIXME: Add the CodePointCount to Column.
FormatTok->WhitespaceRange = SourceRange(
WhitespaceStart, WhitespaceStart.getLocWithOffset(WhitespaceLength));
OpenPOWER on IntegriCloud