Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizations #19

Merged
merged 26 commits into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
48935f3
Optimization: don't create new hash in Renderer#escape
asterite Sep 7, 2019
66c6ea0
Optimization: avoid calling gsub when not needed
asterite Sep 7, 2019
530de4c
Optimization: avoid creating attributes Hash if not needed
asterite Sep 7, 2019
92f850e
Optimization: avoid creating openers_bottom Hash if not needed
asterite Sep 7, 2019
c096d59
Optimization: make Node#data be lazily initialized
asterite Sep 7, 2019
795b0ff
Optimization: extract array literal to constant
asterite Sep 7, 2019
4a8e485
Optimization: avoid double regex match
asterite Sep 7, 2019
eb17b25
Optimization: work at the byte level
asterite Sep 7, 2019
938ae0e
Optimization: perform MAIN rule by hand
asterite Sep 7, 2019
e3d247e
Optimization: avoid allocating unnecessary arrays
asterite Sep 7, 2019
e451a58
Optimization: use `str.ends_with?` instead of `str[-1] ==`
asterite Sep 7, 2019
ee76396
Optimization: use `each_value` instead of `values.each`
asterite Sep 7, 2019
8540dda
Optimization: avoid string interpolation for h1...h6 headings
asterite Sep 7, 2019
c0eb22f
Optimization: avoid string interpolation for lists tag names
asterite Sep 7, 2019
476ef2b
Optimization: there's no need to create an array of lines
asterite Sep 7, 2019
86c700d
Rename `line_size` to `lines_size`
asterite Sep 7, 2019
fb8048d
Optimization: use `String::Builder` instead of `IO::Memory`
asterite Sep 7, 2019
408ab49
Optimization: for escape chars we can use bytes
asterite Sep 7, 2019
ba9d8c4
Optimization: avoid creating Hash when not necessary
asterite Sep 7, 2019
ab2a2d1
Optimization: avoid creating array when not necessary
asterite Sep 7, 2019
5e9d34c
Optimization: `split(/\s+/)` is the same as `split`
asterite Sep 8, 2019
1f83e56
Optimization: match byte_begin + bytesize is just byte_end
asterite Sep 8, 2019
80ae327
Add `end_tag` to `HtmlRenderer#tag`
asterite Sep 8, 2019
16ed2f6
HtmlRenderer headings can be an array
asterite Sep 8, 2019
8688ebb
Optimization: pass capacity to String.build in normalize_uri
asterite Sep 8, 2019
50ee837
Optimization: avoid gsub if not needed in decode_uri
asterite Sep 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/markd/node.cr
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module Markd

property type : Type

property data = {} of String => DataValue
property(data) { {} of String => DataValue }
property source_pos = { {1, 1}, {0, 0} }
property text = ""
property? open = true
Expand Down Expand Up @@ -126,7 +126,10 @@ module Markd
io << " @type=" << @type
io << " @parent=" << @parent if @parent
io << " @next=" << @next if @next
io << " @data=" << @data if @data.size > 0

data = @data
io << " @data=" << data if data && !data.empty?

io << ">"
nil
end
Expand Down
4 changes: 2 additions & 2 deletions src/markd/parsers/block.cr
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ module Markd::Parser
@lines = source.lines
@line_size = @lines.size
# ignore last blank line created by final newline
@line_size -= 1 if source[-1]? == '\n'
@line_size -= 1 if source.ends_with?('\n')
end

private def parse_blocks
Expand Down Expand Up @@ -132,7 +132,7 @@ module Markd::Parser
end
end

matched = RULES.values.each do |rule|
matched = RULES.each_value do |rule|
case rule.match(self, container)
when Rule::MatchValue::Container
container = tip
Expand Down
Loading