* Move handler call inside the inner loop's 'if handler != nil' clause
* Move appender of possible tail bytes outside of loop
* Get rid of outer loop
* Rename i -> beg
Again, this does not seem to gain much performance, but makes the code
significantly more readable.
Rearrange inline parser a little bit to check less conditionals for
every byte.
* Add early check for len(data) == 0
* Move 'for i < len(data)' check inside the (rarer) positive clause of
trigger result handling
* A check for newline turned out to be redundant
* Look up p.inlineCallback only once
All that does not gain much performance in itself, but doesn't hurt and
makes the code structure simpler, which will hopefully allow further
streamlining.
Simplify and optimize escapeHTML as per @Ambrevar's suggestion: lean on
the fact that we're dealing with bytes: declare a 256-element array with
most of it filled with zeros, except for the few slots that need
escaping. This avoids some conditionals in a tight loop.
Also, uncomment it's benchmark.
When passed a non-container root node, the former algorithm would go on
walking down the rest of the tree beyond the root.
The former walk fix was supposed to do that but somehow the code
disappeared in the process.
Some renderers might not care to have an explicit list of footnotes at
the end of the document, instead they're interested in the content of
the footnote at the location of a referer. Make their lives easier by
providing such a link
Using strings in helper functions causes a lot of string-to-[]byte
allocations. This fix is centered around converging the tag() helper
func to the []byte lingo. In order to do that, a lot of string literals
have moved to global variables, where string to []byte conversion can
happen once.
Clean up footnotes part of an AST: don't force HTML-specific pieces
there, just keep a clean list of footnotes. Since some renderers might
want to process footnotes differently, let them know about footnotes by
having a flag on that list.
Move reference and footnote extraction code from firstPass to a
paragraph block parser. This makes firstPass a little bit slimmer, ergo
closer to elimination.
When parseRefsToAST constructs a list of footnotes, it hardcoded the
item flags to ListTypeOrdered and omitted ListItemBeginningOfList.
However, a quick look around indicates that ListItemBeginningOfList
might have lost its meaning altogether in v2 (it used to control item
spacing in v1, which is now extracted from the AST structure). So add a
TODO to clean that up one day.
Most of its body was redundant, as it was moved to parseRefsToAST. After
removal of that code, only a single line remains, so move it out to the
caller of secondPass.
* Only split when inline callbacks consume some bytes
The former hacks around maybeLineBreak and Smartypants are no longer
needed.
The algorithm has been streamlined: shorter, simpler, faster.
The 'currBlock' field of the parser is gone.
* Remove spurious logs
When passed a non-container root node, or when the visitor whould return
SkipChildren for the root node, the former algorithm would go on walking
down the rest of the tree beyond the root.
This commit also removes unneeded functions and variables.