summaryrefslogtreecommitdiff
path: root/src/iterator.c
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2020-01-19 13:46:10 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2020-01-23 08:25:54 -0800
commitf3f50b29d615d2678d8047dc277b108cc5143167 (patch)
treeca3f01f6352d2cc2dd7cfc9c96508b800b8cc510 /src/iterator.c
parent3ef0718f9f4c9dea5014a8a0e9a67e2366b9374f (diff)
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.
Diffstat (limited to 'src/iterator.c')
-rw-r--r--src/iterator.c12
1 files changed, 6 insertions, 6 deletions
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);
}
}