cmark

My personal build of CMark ✏️

Commit
39c3554151d40464cd1694a4013acd1e0188dbc7
Parent
6d27ebf98e4de6bc8422eef495ea86c098c72e67
Author
John MacFarlane <jgm@berkeley.edu>
Date

cmark_consolidate_text_nodes: avoid some unnecessary allocation.

This improves on #32, I think.

@elibarzilay, does this look better? We now avoid the allocations associated with cmark_get_literal, and copy directly from the chunk to the buffer.

Diffstat

1 file changed, 3 insertions, 2 deletions

Status File Name N° Changes Insertions Deletions
Modified src/iterator.c 5 3 2
diff --git a/src/iterator.c b/src/iterator.c
@@ -129,15 +129,16 @@ void cmark_consolidate_text_nodes(cmark_node *root)
 		    cur->next &&
 		    cur->next->type == CMARK_NODE_TEXT) {
 			cmark_strbuf_clear(&buf);
-			cmark_strbuf_puts(&buf, cmark_node_get_literal(cur));
+			cmark_strbuf_put(&buf, cur->as.literal.data, cur->as.literal.len);
 			tmp = cur->next;
 			while (tmp && tmp->type == CMARK_NODE_TEXT) {
 				cmark_iter_next(iter); // advance pointer
-				cmark_strbuf_puts(&buf, cmark_node_get_literal(tmp));
+				cmark_strbuf_put(&buf, tmp->as.literal.data, tmp->as.literal.len);
 				next = tmp->next;
 				cmark_node_free(tmp);
 				tmp = next;
 			}
+			cmark_strbuf_putc(&buf, 0);
 			cmark_node_set_literal(cur, (char *)buf.ptr);
 		}
 	}