Commit 7cb7f65cf09b17041770d8c39f04e0842757ae4f

Martin Mitas 2017-01-01T18:20:25

md_collect_marks: Optimize fast path by some manual loop unrolling.

diff --git a/md4c/md4c.c b/md4c/md4c.c
index 3a8d1cf..ac31d38 100644
--- 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. */