diff options
author | John MacFarlane <[email protected]> | 2017-09-13 20:54:17 -0700 |
---|---|---|
committer | GitHub <[email protected]> | 2017-09-13 20:54:17 -0700 |
commit | ec9db9166f0a931ed2990e531f8e618669b7f8f1 (patch) | |
tree | 405fdcdf0268a3b241661d93bbd0c91861d50b4e /src/blocks.c | |
parent | b9c7a496ba7dd9c3495bae2ff2855899e47b245d (diff) | |
parent | 6c9b4d75cb9e98a7f225e9873045326dffd8b6c6 (diff) |
Merge pull request #232 from github/upstream/refparse
blocks: Fix quadratic behavior in `finalize`
Diffstat (limited to 'src/blocks.c')
-rw-r--r-- | src/blocks.c | 12 |
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 |