md_analyze_line: Optimize scanning for end of line.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
diff --git a/md4c/md4c.c b/md4c/md4c.c
index f8b5311..8682c89 100644
--- 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;