md4c

C Markdown parser. Fast. SAX-like interface. Compliant to CommonMark specification.
git clone https://noulin.net/git/md4c.git
Log | Files | Refs | README | LICENSE

commit 9c644b40dc981265b09ed5071e5bd5621d055f04
parent f1a63f1ca8a7e88f9bef55013033b1b9391108e0
Author: Martin Mitas <mity@morous.org>
Date:   Sun,  1 Jan 2017 17:26:36 +0100

md_analyze_line: Optimize scanning for end of line.

Diffstat:
Mmd4c/md4c.c | 18+++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/md4c/md4c.c b/md4c/md4c.c @@ -5058,7 +5058,7 @@ redo: } #endif } - goto done; + goto done_on_eol; } else { #if 1 /* This is 2nd half of the hack. If the flag is set (that is there @@ -5145,7 +5145,7 @@ redo: } /* Check for indented code. - * Note indented code block cannot interrupt paragraph. */ + * Note indented code block cannot interrupt a paragraph. */ if(line->indent >= ctx->code_indent_offset && (pivot_line->type == MD_LINE_BLANK || pivot_line->type == MD_LINE_INDENTEDCODE)) { @@ -5264,10 +5264,22 @@ redo: } done: - /* Eat rest of the line contents */ + /* Scan for end of the line. + * + * Note this is bottleneck of this function as we itereate over (almost) + * all line contents after some initial line indentation. To optimize, we + * try to eat multiple chars in every loop iteration. + * + * (Measured ~6% performance boost of md2html with this optimization for + * normal kind of input.) + */ + while(off + 4 < ctx->size && !ISNEWLINE(off+0) && !ISNEWLINE(off+1) + && !ISNEWLINE(off+2) && !ISNEWLINE(off+3)) + off += 4; while(off < ctx->size && !ISNEWLINE(off)) off++; +done_on_eol: /* Set end of the line. */ line->end = off;