From 83d4c908045582a803996e4151f9235f09bdf603 Mon Sep 17 00:00:00 2001 From: stephann <3025661+stephannv@users.noreply.github.com> Date: Sat, 19 Oct 2024 16:45:51 -0300 Subject: [PATCH] perf: Improve performance when rendering elements (#86) --- src/blueprint/html/element_registrar.cr | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/blueprint/html/element_registrar.cr b/src/blueprint/html/element_registrar.cr index a797986..699b65a 100644 --- a/src/blueprint/html/element_registrar.cr +++ b/src/blueprint/html/element_registrar.cr @@ -3,15 +3,25 @@ module Blueprint::HTML::ElementRegistrar {% tag ||= method_name.tr("_", "-") %} private def {{method_name.id}}(**attributes, &block) : Nil - element({{tag}}, **attributes) { yield } + @buffer << "<{{tag.id}}" + append_attributes(attributes) + @buffer << ">" + capture_content { yield } + @buffer << "" end private def {{method_name.id}}(**attributes) : Nil - element({{tag}}, "", **attributes) + @buffer << "<{{tag.id}}" + append_attributes(attributes) + @buffer << ">" end private def {{method_name.id}}(__content__, **attributes) : Nil - element({{tag}}, __content__, **attributes) + @buffer << "<{{tag.id}}" + append_attributes(attributes) + @buffer << ">" + append_to_buffer(__content__) + @buffer << "" end end @@ -19,7 +29,9 @@ module Blueprint::HTML::ElementRegistrar {% tag ||= method_name.tr("_", "-") %} private def {{method_name.id}}(**attributes) : Nil - element({{tag}}, "", **attributes) + @buffer << "<{{tag.id}}" + append_attributes(attributes) + @buffer << ">" end end @@ -27,7 +39,9 @@ module Blueprint::HTML::ElementRegistrar {% tag ||= method_name.tr("_", "-") %} private def {{method_name.id}}(**attributes) : Nil - void_element({{tag}}, **attributes) + @buffer << "<{{tag.id}}" + append_attributes(attributes) + @buffer << ">" end end end