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 7cb7f65cf09b17041770d8c39f04e0842757ae4f
parent 2726b7cb5e848a098cef55688932806a16c98bc7
Author: Martin Mitas <mity@morous.org>
Date:   Sun,  1 Jan 2017 18:20:25 +0100

md_collect_marks: Optimize fast path by some manual loop unrolling.

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

diff --git a/md4c/md4c.c b/md4c/md4c.c @@ -2440,14 +2440,24 @@ md_collect_marks(MD_CTX* ctx, const MD_LINE* lines, int n_lines, int table_mode) OFF line_end = line->end; while(off < line_end) { - CHAR ch = CH(off); - - /* Optimization: Fast path. */ - if(ch >= sizeof(ctx->mark_char_map) || !ctx->mark_char_map[(int) ch]) { + CHAR ch; + + /* Optimization: Fast path (with some loop unrolling). */ + if(off + 4 < line_end && + ((unsigned)CH(off+0) >= sizeof(ctx->mark_char_map) || !ctx->mark_char_map[(unsigned) CH(off+0)]) && + ((unsigned)CH(off+1) >= sizeof(ctx->mark_char_map) || !ctx->mark_char_map[(unsigned) CH(off+1)]) && + ((unsigned)CH(off+2) >= sizeof(ctx->mark_char_map) || !ctx->mark_char_map[(unsigned) CH(off+2)]) && + ((unsigned)CH(off+3) >= sizeof(ctx->mark_char_map) || !ctx->mark_char_map[(unsigned) CH(off+3)])) { + off += 4; + continue; + } + if((unsigned)CH(off+0) >= sizeof(ctx->mark_char_map) || !ctx->mark_char_map[(unsigned) CH(off+0)]) { off++; continue; } + ch = CH(off); + /* A backslash escape. * It can go beyond line->end as it may involve escaped new * line to form a hard break. */