From f3f50b29d615d2678d8047dc277b108cc5143167 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Sun, 19 Jan 2020 13:46:10 +0100 Subject: Rearrange struct cmark_node Introduce multi-purpose data/len members in struct cmark_node. This is mainly used to store literal text for inlines, code and HTML blocks. Move the content strbuf for blocks from cmark_node to cmark_parser. When finalizing nodes that allow inlines (paragraphs and headings), detach the strbuf and store the block content in the node's data/len members. Free the block content after processing inlines. Reduces size of struct cmark_node by 8 bytes. --- src/iterator.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/iterator.c') diff --git a/src/iterator.c b/src/iterator.c index cd7db8e..63cbf9e 100644 --- a/src/iterator.c +++ b/src/iterator.c @@ -16,7 +16,7 @@ cmark_iter *cmark_iter_new(cmark_node *root) { if (root == NULL) { return NULL; } - cmark_mem *mem = root->content.mem; + cmark_mem *mem = root->mem; cmark_iter *iter = (cmark_iter *)mem->calloc(1, sizeof(cmark_iter)); iter->mem = mem; iter->root = root; @@ -101,19 +101,19 @@ void cmark_consolidate_text_nodes(cmark_node *root) { if (ev_type == CMARK_EVENT_ENTER && cur->type == CMARK_NODE_TEXT && cur->next && cur->next->type == CMARK_NODE_TEXT) { cmark_strbuf_clear(&buf); - cmark_strbuf_put(&buf, cur->as.literal.data, cur->as.literal.len); + cmark_strbuf_put(&buf, cur->data, cur->len); tmp = cur->next; while (tmp && tmp->type == CMARK_NODE_TEXT) { cmark_iter_next(iter); // advance pointer - cmark_strbuf_put(&buf, tmp->as.literal.data, tmp->as.literal.len); + cmark_strbuf_put(&buf, tmp->data, tmp->len); cur->end_column = tmp->end_column; next = tmp->next; cmark_node_free(tmp); tmp = next; } - iter->mem->free(cur->as.literal.data); - cur->as.literal.len = buf.size; - cur->as.literal.data = cmark_strbuf_detach(&buf); + iter->mem->free(cur->data); + cur->len = buf.size; + cur->data = cmark_strbuf_detach(&buf); } } -- cgit v1.2.3