aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/RawCommentList.cpp
diff options
context:
space:
mode:
authorDmitri Gribenko <gribozavr@gmail.com>2012-07-06 18:19:34 +0000
committerDmitri Gribenko <gribozavr@gmail.com>2012-07-06 18:19:34 +0000
commit811c820257746b1799b790b6adc7804f44154011 (patch)
treea96d9155255424ea05b15f5428216a507daa63bb /lib/AST/RawCommentList.cpp
parent814e219fc6d5faeb48e4fd5375843346f2d4a7a7 (diff)
Don't store pointers into a std::vector (RawCommentList::Comments). Although
currently we take address of std::vector's contents only after we finished adding all comments (so no reallocation can happen), this will change in future. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159845 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/RawCommentList.cpp')
-rw-r--r--lib/AST/RawCommentList.cpp15
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/AST/RawCommentList.cpp b/lib/AST/RawCommentList.cpp
index 791215103f..d67eb0822f 100644
--- a/lib/AST/RawCommentList.cpp
+++ b/lib/AST/RawCommentList.cpp
@@ -176,14 +176,15 @@ bool onlyWhitespaceBetweenComments(SourceManager &SM,
}
} // unnamed namespace
-void RawCommentList::addComment(const RawComment &RC) {
+void RawCommentList::addComment(const RawComment &RC,
+ llvm::BumpPtrAllocator &Allocator) {
if (RC.isInvalid())
return;
// Check if the comments are not in source order.
while (!Comments.empty() &&
!SourceMgr.isBeforeInTranslationUnit(
- Comments.back().getSourceRange().getBegin(),
+ Comments.back()->getSourceRange().getBegin(),
RC.getSourceRange().getBegin())) {
// If they are, just pop a few last comments that don't fit.
// This happens if an \#include directive contains comments.
@@ -204,12 +205,12 @@ void RawCommentList::addComment(const RawComment &RC) {
// If this is the first Doxygen comment, save it (because there isn't
// anything to merge it with).
if (Comments.empty()) {
- Comments.push_back(RC);
+ Comments.push_back(new (Allocator) RawComment(RC));
OnlyWhitespaceSeen = true;
return;
}
- const RawComment &C1 = Comments.back();
+ const RawComment &C1 = *Comments.back();
const RawComment &C2 = RC;
// Merge comments only if there is only whitespace between them.
@@ -221,11 +222,9 @@ void RawCommentList::addComment(const RawComment &RC) {
C1.getEndLine(SourceMgr) + 1 >= C2.getBeginLine(SourceMgr))) {
SourceRange MergedRange(C1.getSourceRange().getBegin(),
C2.getSourceRange().getEnd());
- RawComment Merged(SourceMgr, MergedRange, true);
- Comments.pop_back();
- Comments.push_back(Merged);
+ *Comments.back() = RawComment(SourceMgr, MergedRange, true);
} else
- Comments.push_back(RC);
+ Comments.push_back(new (Allocator) RawComment(RC));
OnlyWhitespaceSeen = true;
}