From 4a66557c297e1e5a71a3da4ceca1969800e7de70 Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Sun, 9 Sep 2012 20:47:31 +0000 Subject: [PATCH] RawCommentList: don't copy the whole new RawComment to LastComment each time. We just need a single SourceLocation for previous comment end. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163482 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/RawCommentList.h | 2 +- lib/AST/RawCommentList.cpp | 30 ++++++++++++++---------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/include/clang/AST/RawCommentList.h b/include/clang/AST/RawCommentList.h index 630626b438..1778ccabb5 100644 --- a/include/clang/AST/RawCommentList.h +++ b/include/clang/AST/RawCommentList.h @@ -188,7 +188,7 @@ public: private: SourceManager &SourceMgr; std::vector Comments; - RawComment LastComment; + SourceLocation PrevCommentEndLoc; bool OnlyWhitespaceSeen; void addCommentsToFront(const std::vector &C) { diff --git a/lib/AST/RawCommentList.cpp b/lib/AST/RawCommentList.cpp index 1003140849..ae5740e5b9 100644 --- a/lib/AST/RawCommentList.cpp +++ b/lib/AST/RawCommentList.cpp @@ -181,26 +181,22 @@ bool containsOnlyWhitespace(StringRef Str) { return Str.find_first_not_of(" \t\f\v\r\n") == StringRef::npos; } -bool onlyWhitespaceBetweenComments(SourceManager &SM, - const RawComment &C1, const RawComment &C2) { - std::pair C1EndLocInfo = SM.getDecomposedLoc( - C1.getSourceRange().getEnd()); - std::pair C2BeginLocInfo = SM.getDecomposedLoc( - C2.getSourceRange().getBegin()); - - // Question does not make sense if comments are located in different files. - if (C1EndLocInfo.first != C2BeginLocInfo.first) +bool onlyWhitespaceBetween(SourceManager &SM, + SourceLocation Loc1, SourceLocation Loc2) { + std::pair Loc1Info = SM.getDecomposedLoc(Loc1); + std::pair Loc2Info = SM.getDecomposedLoc(Loc2); + + // Question does not make sense if locations are in different files. + if (Loc1Info.first != Loc2Info.first) return false; bool Invalid = false; - const char *Buffer = SM.getBufferData(C1EndLocInfo.first, &Invalid).data(); + const char *Buffer = SM.getBufferData(Loc1Info.first, &Invalid).data(); if (Invalid) return false; - StringRef TextBetweenComments(Buffer + C1EndLocInfo.second, - C2BeginLocInfo.second - C1EndLocInfo.second); - - return containsOnlyWhitespace(TextBetweenComments); + StringRef Text(Buffer + Loc1Info.second, Loc2Info.second - Loc1Info.second); + return containsOnlyWhitespace(Text); } } // unnamed namespace @@ -220,11 +216,13 @@ void RawCommentList::addComment(const RawComment &RC, } if (OnlyWhitespaceSeen) { - if (!onlyWhitespaceBetweenComments(SourceMgr, LastComment, RC)) + if (!onlyWhitespaceBetween(SourceMgr, + PrevCommentEndLoc, + RC.getSourceRange().getBegin())) OnlyWhitespaceSeen = false; } - LastComment = RC; + PrevCommentEndLoc = RC.getSourceRange().getEnd(); // Ordinary comments are not interesting for us. if (RC.isOrdinary()) -- 2.40.0