markman

Unnamed repository; edit this file 'description' to name the repository.
git clone git://edryd.org/markman
Log | Files | Refs | LICENSE

commit 97a35f01a17f4e302e14fe5086023f93375bc693
parent ce3bdae82dd4ec5329592b2eb9704e8baf0985b0
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Sun,  6 Jan 2019 15:57:10 -0800

Don't allocate new copied string to create header

Diffstat:
markman.c | 12++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/markman.c b/markman.c @@ -186,13 +186,12 @@ markman_parse(char *src) case '#': for (; *src && *(++src) == '#'; lvl++); src += strspn(src, WS); - s = ecalloc(strcspn(src, "\n") + 1, sizeof(char)); - for (i = 0; *src && *src != '\n'; src++, i++) - s[i] = *src; + s = src; + src += strcspn(src, "\n"); + *src = '\0'; ret = mk_header(lvl, line_parse((s[0] != '-') ? str_cap(s) : s, STR)); if (lvl >= 4) ret->v.h.l->t = BOLD; - free(s); ret->next = markman_parse(++src); return ret; case '\n': @@ -236,10 +235,11 @@ markman_parse(char *src) if (*src == '\n' && src[1] == '\n') { s[i+1] = '\0'; break; - } else if (*src == '\n') + } else if (*src == '\n') { s[i] = ' '; - else + } else { s[i] = *src; + } src += strspn(src, WS); ret = mk_para(line_parse(s, STR)); ret->next = markman_parse(src);