summaryrefslogtreecommitdiff
path: root/src/blocks.c
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2017-09-07 08:06:11 -0700
committerAshe Connor <ashe@kivikakk.ee>2017-09-14 11:57:43 +1000
commit6c9b4d75cb9e98a7f225e9873045326dffd8b6c6 (patch)
tree405fdcdf0268a3b241661d93bbd0c91861d50b4e /src/blocks.c
parentb9c7a496ba7dd9c3495bae2ff2855899e47b245d (diff)
blocks: Fix quadratic behavior in `finalize`
Diffstat (limited to 'src/blocks.c')
-rw-r--r--src/blocks.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/blocks.c b/src/blocks.c
index 5a293b2..3e810bc 100644
--- a/src/blocks.c
+++ b/src/blocks.c
@@ -255,17 +255,21 @@ static cmark_node *finalize(cmark_parser *parser, cmark_node *b) {
switch (S_type(b)) {
case CMARK_NODE_PARAGRAPH:
- while (cmark_strbuf_at(node_content, 0) == '[' &&
- (pos = cmark_parse_reference_inline(parser->mem, node_content,
- parser->refmap))) {
+ {
+ cmark_chunk chunk = {node_content->ptr, node_content->size, 0};
+ while (chunk.len && chunk.data[0] == '[' &&
+ (pos = cmark_parse_reference_inline(parser->mem, &chunk, parser->refmap))) {
- cmark_strbuf_drop(node_content, pos);
+ chunk.data += pos;
+ chunk.len -= pos;
}
+ cmark_strbuf_drop(node_content, (node_content->size - chunk.len));
if (is_blank(node_content, 0)) {
// remove blank node (former reference def)
cmark_node_free(b);
}
break;
+ }
case CMARK_NODE_CODE_BLOCK:
if (!b->as.code.fenced) { // indented code