r207087 - Comment to XML conversion: use unique_ptr for SimpleFormatContext

David Blaikie dblaikie at gmail.com
Thu Apr 24 07:16:51 PDT 2014


On Thu, Apr 24, 2014 at 12:52 AM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
> Author: gribozavr
> Date: Thu Apr 24 02:52:31 2014
> New Revision: 207087
>
> URL: http://llvm.org/viewvc/llvm-project?rev=207087&view=rev
> Log:
> Comment to XML conversion: use unique_ptr for SimpleFormatContext

Any reason this couldn't just be an Optional<SimpleFormatContext>?

Judging by the comments this might not even need to be optional - it
just needs a way to shrink/dispose of some buffers? That should be
achievable without having to destroy an object... but I haven't looked
in detail at where the side effects are. I guess it's the underlying
SourceManager that needs some way to reset.

>
> Modified:
>     cfe/trunk/include/clang/Index/CommentToXML.h
>     cfe/trunk/lib/Index/CommentToXML.cpp
>
> Modified: cfe/trunk/include/clang/Index/CommentToXML.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/CommentToXML.h?rev=207087&r1=207086&r2=207087&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Index/CommentToXML.h (original)
> +++ cfe/trunk/include/clang/Index/CommentToXML.h Thu Apr 24 02:52:31 2014
> @@ -11,6 +11,7 @@
>  #define LLVM_CLANG_INDEX_COMMENTTOXML_H
>
>  #include "clang/Basic/LLVM.h"
> +#include <memory>
>
>  namespace clang {
>  class ASTContext;
> @@ -24,11 +25,11 @@ namespace index {
>  class SimpleFormatContext;
>
>  class CommentToXMLConverter {
> -  SimpleFormatContext *FormatContext;
> +  std::unique_ptr<SimpleFormatContext> FormatContext;
>    unsigned FormatInMemoryUniqueId;
>
>  public:
> -  CommentToXMLConverter() : FormatContext(0), FormatInMemoryUniqueId(0) {}
> +  CommentToXMLConverter();
>    ~CommentToXMLConverter();
>
>    void convertCommentToHTML(const comments::FullComment *FC,
>
> Modified: cfe/trunk/lib/Index/CommentToXML.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/CommentToXML.cpp?rev=207087&r1=207086&r2=207087&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Index/CommentToXML.cpp (original)
> +++ cfe/trunk/lib/Index/CommentToXML.cpp Thu Apr 24 02:52:31 2014
> @@ -1136,9 +1136,8 @@ void CommentASTToXMLConverter::appendToR
>    Result << "]]>";
>  }
>
> -CommentToXMLConverter::~CommentToXMLConverter() {
> -  delete FormatContext;
> -}
> +CommentToXMLConverter::CommentToXMLConverter() : FormatInMemoryUniqueId(0) {}
> +CommentToXMLConverter::~CommentToXMLConverter() = default;
>
>  void CommentToXMLConverter::convertCommentToHTML(const FullComment *FC,
>                                                   SmallVectorImpl<char> &HTML,
> @@ -1159,13 +1158,10 @@ void CommentToXMLConverter::convertHTMLT
>  void CommentToXMLConverter::convertCommentToXML(const FullComment *FC,
>                                                  SmallVectorImpl<char> &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(),
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list