Skip to content

Commit

Permalink
perf: Use String::Builder to improve render times
Browse files Browse the repository at this point in the history
  • Loading branch information
stephannv committed Sep 8, 2024
1 parent 3fb5269 commit a9c99cf
Show file tree
Hide file tree
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
Expand Up @@ -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?
Expand Down
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
Expand Down
4 changes: 2 additions & 2 deletions src/blueprint/html/renderer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a9c99cf

Please sign in to comment.