diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-07-25 15:50:55 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-07-25 15:51:19 -0700 |
commit | 2c8ce48a3c75a28ac2f5bee5a2d3b8cfda5e66b3 (patch) | |
tree | 3237d14d8c5e8cfaf1f3a1f81a83c26034be3831 | |
parent | 7bfb3ad4fa39e1461f0579d2fd8aaaab293996e8 (diff) |
commonmark renderer - use regular sprintf for list markers.
This avoids an allocation and use of strbuf_printf.
-rw-r--r-- | src/commonmark.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/commonmark.c b/src/commonmark.c index 0f4c2bc..6462db9 100644 --- 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: |