cmark

My personal build of CMark ✏️

Commit
2c8ce48a3c75a28ac2f5bee5a2d3b8cfda5e66b3
Parent
7bfb3ad4fa39e1461f0579d2fd8aaaab293996e8
Author
John MacFarlane <jgm@berkeley.edu>
Date

commonmark renderer - use regular sprintf for list markers.

This avoids an allocation and use of strbuf_printf.

Diffstat

1 file changed, 8 insertions, 9 deletions

Status File Name N° Changes Insertions Deletions
Modified src/commonmark.c 17 8 9
diff --git a/src/commonmark.c b/src/commonmark.c
@@ -171,7 +171,7 @@ S_render_node(cmark_renderer *renderer,
 	bool entering = (ev_type == CMARK_EVENT_ENTER);
 	const char *info, *code, *title;
 	size_t info_len, code_len;
-	cmark_strbuf listmarker = GH_BUF_INIT;
+	char listmarker[20];
 	char *emph_delim;
 	bufsize_t marker_width;
 
@@ -230,12 +230,12 @@ S_render_node(cmark_renderer *renderer,
 			// we ensure a width of at least 4 so
 			// we get nice transition from single digits
 			// to double
-			cmark_strbuf_printf(&listmarker,
-			                    "%d%s%s", list_number,
-			                    list_delim == CMARK_PAREN_DELIM ?
-			                    ")" : ".",
-			                    list_number < 10 ? "  " : " ");
-			marker_width = listmarker.size;
+			sprintf(listmarker,
+				"%d%s%s", list_number,
+				list_delim == CMARK_PAREN_DELIM ?
+				")" : ".",
+				list_number < 10 ? "  " : " ");
+			marker_width = safe_strlen(listmarker);
 		}
 		if (entering) {
 			if (cmark_node_get_list_type(node->parent) ==
@@ -243,7 +243,7 @@ S_render_node(cmark_renderer *renderer,
 				LIT("* ");
 				cmark_strbuf_puts(renderer->prefix, "  ");
 			} else {
-				LIT((char *)listmarker.ptr);
+				LIT(listmarker);
 				for (i = marker_width; i--;) {
 					cmark_strbuf_putc(renderer->prefix, ' ');
 				}
@@ -254,7 +254,6 @@ S_render_node(cmark_renderer *renderer,
 			                      marker_width);
 			CR();
 		}
-		cmark_strbuf_free(&listmarker);
 		break;
 
 	case CMARK_NODE_HEADER: