md_is_inline_link_spec: Use md_lookup_line() instead of walking. Fixes #236.
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 47 48 49 50
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cf22807..295e84a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,15 @@
# MD4C Change Log
+## Next Version (Work in Progress)
+
+Fixes:
+
+ - [#236](https://github.com/mity/md4c/issues/236):
+ Fix quadratic time behavior caused by one-by-one walking over block lines
+ instead of calling `md_lookup_line()`.
+
+
## Version 0.5.2
Changes:
diff --git a/src/md4c.c b/src/md4c.c
index 812bde5..cb44e3d 100644
--- a/src/md4c.c
+++ b/src/md4c.c
@@ -2332,8 +2332,7 @@ md_is_inline_link_spec(MD_CTX* ctx, const MD_LINE* lines, MD_SIZE n_lines,
OFF off = beg;
int ret = FALSE;
- while(off >= lines[line_index].end)
- line_index++;
+ md_lookup_line(off, lines, n_lines, &line_index);
MD_ASSERT(CH(off) == _T('('));
off++;
diff --git a/test/pathological-tests.py b/test/pathological-tests.py
index d72453d..924cbe9 100644
--- a/test/pathological-tests.py
+++ b/test/pathological-tests.py
@@ -99,7 +99,10 @@ pathological = {
"huge table":
(("th|" * 10000 + "\n" + "-|" * 10000 + "\n" + "td\n" * 10000),
re.compile(""),
- "--ftables")
+ "--ftables"),
+ "many broken links":
+ (("]([\n" * 50000),
+ re.compile("<p>(\]\(\[\r?\n){49999}\]\(\[</p>"))
}
whitespace_re = re.compile('/s+/')