aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
diff options
context:
space:
mode:
authorPaul Kirth <paulkirth@google.com>2025-09-15 16:26:11 -0700
committerPaul Kirth <paulkirth@google.com>2025-09-25 18:52:04 -0700
commit2a32dcd09cc7aa2c06c16ad59b499a12d3b75e30 (patch)
treef710768792949a3ae5e2beea8b1eea0881d69383 /clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
parentc2719fb07a57981f22a3c84eb6649ef0ebc7cd18 (diff)
downloadllvm-users/ilovepi/mustache-ast-arena.zip
llvm-users/ilovepi/mustache-ast-arena.tar.gz
llvm-users/ilovepi/mustache-ast-arena.tar.bz2
[llvm][mustache] Use BumpPtrAllocator to save ASTNodesusers/ilovepi/mustache-ast-arena
We make the Mustache ASTNodes usable in the arena by first removing all of the memory owning data structures, like std::vector, std::unique_ptr, and SmallVector. We use standard LLVM list types to hold this data instead, and make use of a UniqueStringSaver to hold the various templates strings. Additionally, update clang-doc APIs to use the new interfaces. Future work can make better use of Twine interfaces to help avoid any intermediate copies or allocations.
Diffstat (limited to 'clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp')
-rw-r--r--clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
index b37dc27..b4b9322 100644
--- a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
@@ -46,7 +46,13 @@ public:
const ClangDocContext &CDCtx) override;
};
-class MustacheTemplateFile : public Template {
+class MustacheTemplateFile {
+ BumpPtrAllocator Allocator;
+ StringSaver Saver;
+ MustacheContext Ctx;
+ Template T;
+ std::unique_ptr<MemoryBuffer> Buffer;
+
public:
static Expected<std::unique_ptr<MustacheTemplateFile>>
createMustacheFile(StringRef FileName) {
@@ -54,10 +60,8 @@ public:
MemoryBuffer::getFile(FileName);
if (auto EC = BufferOrError.getError())
return createFileOpenError(FileName, EC);
-
- std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOrError.get());
- StringRef FileContent = Buffer->getBuffer();
- return std::make_unique<MustacheTemplateFile>(FileContent);
+ return std::make_unique<MustacheTemplateFile>(
+ std::move(BufferOrError.get()));
}
Error registerPartialFile(StringRef Name, StringRef FileName) {
@@ -68,11 +72,15 @@ public:
std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOrError.get());
StringRef FileContent = Buffer->getBuffer();
- registerPartial(Name.str(), FileContent.str());
+ T.registerPartial(Name.str(), FileContent.str());
return Error::success();
}
- MustacheTemplateFile(StringRef TemplateStr) : Template(TemplateStr) {}
+ void render(json::Value &V, raw_ostream &OS) { T.render(V, OS); }
+
+ MustacheTemplateFile(std::unique_ptr<MemoryBuffer> &&B)
+ : Saver(Allocator), Ctx(Allocator, Saver), T(B->getBuffer(), Ctx),
+ Buffer(std::move(B)) {}
};
static std::unique_ptr<MustacheTemplateFile> NamespaceTemplate = nullptr;