88static const std::string LongHtmlString = [] {
99 std::string S;
1010 S.reserve (500000 );
11- for (int i = 0 ; i < 50000 ; ++i ) {
11+ for (int Idx = 0 ; Idx < 50000 ; ++Idx ) {
1212 S += " <script>alert('xss');</script>" ;
1313 }
1414 return S;
@@ -153,7 +153,11 @@ static const std::string LargeOutputStringTemplate = "{{long_string}}";
153153// syntaxes.
154154static void BM_Mustache_StringRendering (benchmark::State &state,
155155 const std::string &TplStr) {
156- llvm::mustache::Template Tpl (TplStr);
156+ llvm::BumpPtrAllocator Allocator;
157+ llvm::StringSaver Saver (Allocator);
158+ llvm::mustache::MustacheContext Ctx (Allocator, Saver);
159+
160+ llvm::mustache::Template Tpl (TplStr, Ctx);
157161 llvm::json::Value Data =
158162 llvm::json::Object ({{" content" , llvm::json::Value (LongHtmlString)}});
159163 for (auto _ : state) {
@@ -172,7 +176,11 @@ BENCHMARK_CAPTURE(BM_Mustache_StringRendering, Unescaped_Ampersand,
172176// Tests the "hot render" cost of repeatedly traversing a deep and wide
173177// JSON object.
174178static void BM_Mustache_DeepTraversal (benchmark::State &state) {
175- llvm::mustache::Template Tpl (DeepTraversalTemplate);
179+ llvm::BumpPtrAllocator Allocator;
180+ llvm::StringSaver Saver (Allocator);
181+ llvm::mustache::MustacheContext Ctx (Allocator, Saver);
182+
183+ llvm::mustache::Template Tpl (DeepTraversalTemplate, Ctx);
176184 for (auto _ : state) {
177185 std::string Result;
178186 llvm::raw_string_ostream OS (Result);
@@ -184,7 +192,12 @@ BENCHMARK(BM_Mustache_DeepTraversal);
184192
185193// Tests the "hot render" cost of pushing and popping a deep context stack.
186194static void BM_Mustache_DeeplyNestedRendering (benchmark::State &state) {
187- llvm::mustache::Template Tpl (DeeplyNestedRenderingTemplate);
195+
196+ llvm::BumpPtrAllocator Allocator;
197+ llvm::StringSaver Saver (Allocator);
198+ llvm::mustache::MustacheContext Ctx (Allocator, Saver);
199+
200+ llvm::mustache::Template Tpl (DeeplyNestedRenderingTemplate, Ctx);
188201 for (auto _ : state) {
189202 std::string Result;
190203 llvm::raw_string_ostream OS (Result);
@@ -197,7 +210,11 @@ BENCHMARK(BM_Mustache_DeeplyNestedRendering);
197210// Tests the performance of the loop logic when iterating over a huge number of
198211// items.
199212static void BM_Mustache_HugeArrayIteration (benchmark::State &state) {
200- llvm::mustache::Template Tpl (HugeArrayIterationTemplate);
213+ llvm::BumpPtrAllocator Allocator;
214+ llvm::StringSaver Saver (Allocator);
215+ llvm::mustache::MustacheContext Ctx (Allocator, Saver);
216+
217+ llvm::mustache::Template Tpl (HugeArrayIterationTemplate, Ctx);
201218 for (auto _ : state) {
202219 std::string Result;
203220 llvm::raw_string_ostream OS (Result);
@@ -209,25 +226,37 @@ BENCHMARK(BM_Mustache_HugeArrayIteration);
209226
210227// Tests the performance of the parser on a large, "wide" template.
211228static void BM_Mustache_ComplexTemplateParsing (benchmark::State &state) {
229+ llvm::BumpPtrAllocator Allocator;
230+ llvm::StringSaver Saver (Allocator);
231+ llvm::mustache::MustacheContext Ctx (Allocator, Saver);
232+
212233 for (auto _ : state) {
213- llvm::mustache::Template Tpl (ComplexTemplateParsingTemplate);
234+ llvm::mustache::Template Tpl (ComplexTemplateParsingTemplate, Ctx );
214235 benchmark::DoNotOptimize (Tpl);
215236 }
216237}
217238BENCHMARK (BM_Mustache_ComplexTemplateParsing);
218239
219240// Tests the performance of the parser on a small, "deep" template.
220241static void BM_Mustache_SmallTemplateParsing (benchmark::State &state) {
242+ llvm::BumpPtrAllocator Allocator;
243+ llvm::StringSaver Saver (Allocator);
244+ llvm::mustache::MustacheContext Ctx (Allocator, Saver);
245+
221246 for (auto _ : state) {
222- llvm::mustache::Template Tpl (SmallTemplateParsingTemplate);
247+ llvm::mustache::Template Tpl (SmallTemplateParsingTemplate, Ctx );
223248 benchmark::DoNotOptimize (Tpl);
224249 }
225250}
226251BENCHMARK (BM_Mustache_SmallTemplateParsing);
227252
228253// Tests the performance of rendering a template that includes a partial.
229254static void BM_Mustache_PartialsRendering (benchmark::State &state) {
230- llvm::mustache::Template Tpl (ComplexPartialTemplate);
255+ llvm::BumpPtrAllocator Allocator;
256+ llvm::StringSaver Saver (Allocator);
257+ llvm::mustache::MustacheContext Ctx (Allocator, Saver);
258+
259+ llvm::mustache::Template Tpl (ComplexPartialTemplate, Ctx);
231260 Tpl.registerPartial (" item_partial" , ItemPartialTemplate);
232261 llvm::json::Value Data = HugeArrayData;
233262
@@ -243,7 +272,11 @@ BENCHMARK(BM_Mustache_PartialsRendering);
243272// Tests the performance of the underlying buffer management when generating a
244273// very large output.
245274static void BM_Mustache_LargeOutputString (benchmark::State &state) {
246- llvm::mustache::Template Tpl (LargeOutputStringTemplate);
275+ llvm::BumpPtrAllocator Allocator;
276+ llvm::StringSaver Saver (Allocator);
277+ llvm::mustache::MustacheContext Ctx (Allocator, Saver);
278+
279+ llvm::mustache::Template Tpl (LargeOutputStringTemplate, Ctx);
247280 for (auto _ : state) {
248281 std::string Result;
249282 llvm::raw_string_ostream OS (Result);
0 commit comments