summaryrefslogtreecommitdiff
path: root/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
commit4b762a91faac0473fa380ea9731992b24867e2e6 (patch)
tree6d344280ae5eb09743ba4d35ef844af730217776 /lib/Format/Format.cpp
parent3361f10d6b21327b082c53facef0741c13b2ffa7 (diff)
downloadclang-4b762a91faac0473fa380ea9731992b24867e2e6.tar.gz
clang-4b762a91faac0473fa380ea9731992b24867e2e6.tar.bz2
clang-4b762a91faac0473fa380ea9731992b24867e2e6.tar.xz
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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189758 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r--lib/Format/Format.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 84bf36c7fd..39d2c0f96c 100644
--- a/lib/Format/Format.cpp
+++ b/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));