tlbuf: do not use an sbuf struct in lbuf_rd() - neatvi - [fork] simple vi-type … | |
git clone git://src.adamsgaard.dk/neatvi | |
Log | |
Files | |
Refs | |
README | |
--- | |
commit d77ba570505085a2c006463b174d6fc6da62b3d5 | |
parent d45220ca72fc434031d68ec33a553de6ebf0262e | |
Author: Ali Gholami Rudi <[email protected]> | |
Date: Thu, 11 Jun 2015 15:42:25 +0430 | |
lbuf: do not use an sbuf struct in lbuf_rd() | |
Diffstat: | |
M lbuf.c | 19 ++++++++----------- | |
1 file changed, 8 insertions(+), 11 deletions(-) | |
--- | |
diff --git a/lbuf.c b/lbuf.c | |
t@@ -79,20 +79,17 @@ static void lbuf_insertline(struct lbuf *lb, int pos, char… | |
/* low-level insertion */ | |
static void lbuf_insert(struct lbuf *lb, int pos, char *s) | |
{ | |
- int len = strlen(s); | |
- struct sbuf *sb; | |
int lb_len = lbuf_len(lb); | |
int beg = pos, end; | |
+ char *r; | |
int i; | |
- sb = sbuf_make(); | |
- for (i = 0; i < len; i++) { | |
- sbuf_chr(sb, (unsigned char) s[i]); | |
- if (s[i] == '\n') { | |
- lbuf_insertline(lb, pos++, sbuf_done(sb)); | |
- sb = sbuf_make(); | |
- } | |
+ while ((r = strchr(s, '\n'))) { | |
+ char *n = malloc(r - s + 2); | |
+ memcpy(n, s, r - s + 1); | |
+ n[r - s + 1] = '\0'; | |
+ lbuf_insertline(lb, pos++, n); | |
+ s = r + 1; | |
} | |
- sbuf_free(sb); | |
for (i = 0; i < LEN(lb->mark); i++) /* updating marks */ | |
if (lb->mark[i] >= pos) | |
lb->mark[i] += lbuf_len(lb) - lb_len; | |
t@@ -152,7 +149,7 @@ static void lbuf_opt(struct lbuf *lb, int ins, int beg, in… | |
void lbuf_rd(struct lbuf *lbuf, int fd, int pos) | |
{ | |
- char buf[1 << 8]; | |
+ char buf[1 << 10]; | |
struct sbuf *sb; | |
int nr; | |
sb = sbuf_make(); |