From 4f4dd17d056b02eaa64adf1cad99e14eceabde1b Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Thu, 24 Apr 2014 07:52:31 +0000 Subject: Comment to XML conversion: use unique_ptr for SimpleFormatContext llvm-svn: 207087 --- clang/lib/Index/CommentToXML.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'clang/lib/Index/CommentToXML.cpp') diff --git a/clang/lib/Index/CommentToXML.cpp b/clang/lib/Index/CommentToXML.cpp index 54087bd..a668c56 100644 --- a/clang/lib/Index/CommentToXML.cpp +++ b/clang/lib/Index/CommentToXML.cpp @@ -1136,9 +1136,8 @@ void CommentASTToXMLConverter::appendToResultWithCDATAEscaping(StringRef S) { Result << "]]>"; } -CommentToXMLConverter::~CommentToXMLConverter() { - delete FormatContext; -} +CommentToXMLConverter::CommentToXMLConverter() : FormatInMemoryUniqueId(0) {} +CommentToXMLConverter::~CommentToXMLConverter() = default; void CommentToXMLConverter::convertCommentToHTML(const FullComment *FC, SmallVectorImpl &HTML, @@ -1159,13 +1158,10 @@ void CommentToXMLConverter::convertHTMLTagNodeToText( void CommentToXMLConverter::convertCommentToXML(const FullComment *FC, SmallVectorImpl &XML, const ASTContext &Context) { - if (!FormatContext) { - FormatContext = new SimpleFormatContext(Context.getLangOpts()); - } else if ((FormatInMemoryUniqueId % 1000) == 0) { - // Delete after some number of iterations, so the buffers don't grow - // too large. - delete FormatContext; - FormatContext = new SimpleFormatContext(Context.getLangOpts()); + if (!FormatContext || (FormatInMemoryUniqueId % 1000) == 0) { + // Create a new format context, or re-create it after some number of + // iterations, so the buffers don't grow too large. + FormatContext.reset(new SimpleFormatContext(Context.getLangOpts())); } CommentASTToXMLConverter Converter(FC, XML, Context.getCommentCommandTraits(), -- cgit v1.1