Ensure render tag checks for most common type first

Previously, render tag would check if a template
responded to `:to_partial` before checking if its
name was a string. As `is_a?(String)` instances are
more common that `to_partial`, this commit reorders
the conditional to follow the common path
This commit is contained in:
Julia Boutin
2025-11-04 13:11:18 -07:00
parent 248f3a412f
commit e753b9025d
+5 -5
View File
@@ -49,14 +49,14 @@ module Liquid
def render_tag(context, output)
template = context.evaluate(@template_name_expr)
if template.respond_to?(:to_partial)
partial = template.to_partial
template_name = template.filename
context_variable_name = @alias_name || template.name
elsif @template_name_expr.is_a?(String)
if @template_name_expr.is_a?(String)
partial = PartialCache.load(template, context: context, parse_context: parse_context)
template_name = partial.name
context_variable_name = @alias_name || template_name.split('/').last
elsif template.respond_to?(:to_partial) && template.respond_to?(:name)
partial = template.to_partial
template_name = template.filename
context_variable_name = @alias_name || template.name
else
raise ::ArgumentError
end