[cfe-commits] r160400 - /cfe/trunk/lib/AST/ASTContext.cpp
Dmitri Gribenko
gribozavr at gmail.com
Tue Jul 17 15:01:09 PDT 2012
Author: gribozavr
Date: Tue Jul 17 17:01:09 2012
New Revision: 160400
URL: http://llvm.org/viewvc/llvm-project?rev=160400&view=rev
Log:
Implement an optimization for finding the comment that occurs just after a
given declaration.
It is based on the observation that during parsing the comment that should be
attached to the decl is usually among the last two documentation comments
parsed.
Modified:
cfe/trunk/lib/AST/ASTContext.cpp
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=160400&r1=160399&r2=160400&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Jul 17 17:01:09 2012
@@ -97,12 +97,30 @@
return NULL;
// Find the comment that occurs just after this declaration.
- RawComment CommentAtDeclLoc(SourceMgr, SourceRange(DeclLoc));
- ArrayRef<RawComment *>::iterator Comment
- = std::lower_bound(RawComments.begin(),
- RawComments.end(),
- &CommentAtDeclLoc,
- BeforeThanCompare<RawComment>(SourceMgr));
+ ArrayRef<RawComment *>::iterator Comment;
+ {
+ // When searching for comments during parsing, the comment we are looking
+ // for is usually among the last two comments we parsed -- check them
+ // first.
+ RawComment CommentAtDeclLoc(SourceMgr, SourceRange(DeclLoc));
+ BeforeThanCompare<RawComment> Compare(SourceMgr);
+ ArrayRef<RawComment *>::iterator MaybeBeforeDecl = RawComments.end() - 1;
+ bool Found = Compare(*MaybeBeforeDecl, &CommentAtDeclLoc);
+ if (!Found && RawComments.size() >= 2) {
+ MaybeBeforeDecl--;
+ Found = Compare(*MaybeBeforeDecl, &CommentAtDeclLoc);
+ }
+
+ if (Found) {
+ Comment = MaybeBeforeDecl + 1;
+ assert(Comment == std::lower_bound(RawComments.begin(), RawComments.end(),
+ &CommentAtDeclLoc, Compare));
+ } else {
+ // Slow path.
+ Comment = std::lower_bound(RawComments.begin(), RawComments.end(),
+ &CommentAtDeclLoc, Compare);
+ }
+ }
// Decompose the location for the declaration and find the beginning of the
// file buffer.
More information about the cfe-commits
mailing list