From e3fc735de78d6822d15c0698cc67846ec4427fb6 Mon Sep 17 00:00:00 2001 From: Tobi Lutke Date: Wed, 11 Mar 2026 10:23:56 -0400 Subject: [PATCH] =?UTF-8?q?Cache=20block=5Fdelimiter=20strings=20per=20tag?= =?UTF-8?q?=20name=20=E2=80=94=20avoids=20repeated=20string=20interpolatio?= =?UTF-8?q?n\n\nResult:=20{"status":"keep","combined=5F=C2=B5s":4372,"pars?= =?UTF-8?q?e=5F=C2=B5s":3127,"render=5F=C2=B5s":1245,"allocations":25605}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/liquid/block.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/liquid/block.rb b/lib/liquid/block.rb index 73d86c7b..19a76cb3 100644 --- a/lib/liquid/block.rb +++ b/lib/liquid/block.rb @@ -60,8 +60,11 @@ module Liquid @tag_name end + # Cache block delimiters per tag name to avoid repeated string allocation + BLOCK_DELIMITER_CACHE = Hash.new { |h, k| h[k] = "end#{k}".freeze } + def block_delimiter - @block_delimiter ||= "end#{block_name}" + @block_delimiter ||= BLOCK_DELIMITER_CACHE[block_name] end private