Introduction
Introduction Statistics Contact Development Disclaimer Help
tsbuf: extend the buffer more eagerly - neatvi - [fork] simple vi-type editor w…
git clone git://src.adamsgaard.dk/neatvi
Log
Files
Refs
README
---
commit d45220ca72fc434031d68ec33a553de6ebf0262e
parent 5266f5c8be4e977eaac06ea4a978d13c9b378d28
Author: Ali Gholami Rudi <[email protected]>
Date: Thu, 11 Jun 2015 15:41:18 +0430
sbuf: extend the buffer more eagerly
Diffstat:
M sbuf.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
---
diff --git a/sbuf.c b/sbuf.c
t@@ -7,6 +7,7 @@
#define SBUFSZ 128
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1))
+#define NEXTSZ(o, r) ALIGN(MAX((o) * 2, (o) + (r)), SBUFSZ)
struct sbuf {
char *s; /* allocated buffer */
t@@ -55,14 +56,14 @@ void sbuf_free(struct sbuf *sb)
void sbuf_chr(struct sbuf *sbuf, int c)
{
if (sbuf->s_n + 2 >= sbuf->s_sz)
- sbuf_extend(sbuf, sbuf->s_sz + SBUFSZ);
+ sbuf_extend(sbuf, NEXTSZ(sbuf->s_sz, 1));
sbuf->s[sbuf->s_n++] = c;
}
void sbuf_mem(struct sbuf *sbuf, char *s, int len)
{
if (sbuf->s_n + len + 1 >= sbuf->s_sz)
- sbuf_extend(sbuf, ALIGN(sbuf->s_n + len + 1, SBUFSZ));
+ sbuf_extend(sbuf, NEXTSZ(sbuf->s_sz, len + 1));
memcpy(sbuf->s + sbuf->s_n, s, len);
sbuf->s_n += len;
}
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.