Skip to content

Commit

Permalink
perf: Use String::Builder to improve render times (#51)
Browse files Browse the repository at this point in the history
stephannv authored Sep 8, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 3fb5269 commit ed3c6bc
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/blueprint/html.cr
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ require "./html/svg"
require "./html/utils"

module Blueprint::HTML
@buffer = IO::Memory.new
@buffer = String::Builder.new

def to_html : String
return "" unless render?
4 changes: 2 additions & 2 deletions src/blueprint/html/content_capture.cr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Blueprint::HTML
private def capture_content(&) : Nil
buffer_size_before_block_evaluation = @buffer.size
buffer_size_before_block_evaluation = @buffer.bytesize
content = with self yield
if buffer_size_before_block_evaluation == @buffer.size
if buffer_size_before_block_evaluation == @buffer.bytesize
::HTML.escape(content.to_s, @buffer)
end
end
4 changes: 2 additions & 2 deletions src/blueprint/html/renderer.cr
Original file line number Diff line number Diff line change
@@ -10,14 +10,14 @@ module Blueprint::HTML
end
end

protected def render_to(buffer : IO::Memory) : Nil
protected def render_to(buffer : String::Builder) : Nil
return unless render?

@buffer = buffer
blueprint
end

protected def render_to(buffer : IO::Memory, &) : Nil
protected def render_to(buffer : String::Builder, &) : Nil
return unless render?

@buffer = buffer

0 comments on commit ed3c6bc

Please sign in to comment.