[cfe-commits] r163482 - in /cfe/trunk: include/clang/AST/RawCommentList.h lib/AST/RawCommentList.cpp

Dmitri Gribenko gribozavr at gmail.com
Sun Sep 9 13:47:31 PDT 2012


Author: gribozavr
Date: Sun Sep  9 15:47:31 2012
New Revision: 163482

URL: http://llvm.org/viewvc/llvm-project?rev=163482&view=rev
Log:
RawCommentList: don't copy the whole new RawComment to LastComment each time.
We just need a single SourceLocation for previous comment end.

Modified:
    cfe/trunk/include/clang/AST/RawCommentList.h
    cfe/trunk/lib/AST/RawCommentList.cpp

Modified: cfe/trunk/include/clang/AST/RawCommentList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RawCommentList.h?rev=163482&r1=163481&r2=163482&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/RawCommentList.h (original)
+++ cfe/trunk/include/clang/AST/RawCommentList.h Sun Sep  9 15:47:31 2012
@@ -188,7 +188,7 @@
 private:
   SourceManager &SourceMgr;
   std::vector<RawComment *> Comments;
-  RawComment LastComment;
+  SourceLocation PrevCommentEndLoc;
   bool OnlyWhitespaceSeen;
 
   void addCommentsToFront(const std::vector<RawComment *> &C) {

Modified: cfe/trunk/lib/AST/RawCommentList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RawCommentList.cpp?rev=163482&r1=163481&r2=163482&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RawCommentList.cpp (original)
+++ cfe/trunk/lib/AST/RawCommentList.cpp Sun Sep  9 15:47:31 2012
@@ -181,26 +181,22 @@
   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<FileID, unsigned> C1EndLocInfo = SM.getDecomposedLoc(
-                                                C1.getSourceRange().getEnd());
-  std::pair<FileID, unsigned> C2BeginLocInfo = SM.getDecomposedLoc(
-                                              C2.getSourceRange().getBegin());
+bool onlyWhitespaceBetween(SourceManager &SM,
+                           SourceLocation Loc1, SourceLocation Loc2) {
+  std::pair<FileID, unsigned> Loc1Info = SM.getDecomposedLoc(Loc1);
+  std::pair<FileID, unsigned> Loc2Info = SM.getDecomposedLoc(Loc2);
 
-  // Question does not make sense if comments are located in different files.
-  if (C1EndLocInfo.first != C2BeginLocInfo.first)
+  // 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 @@
   }
 
   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())





More information about the cfe-commits mailing list