Introduction
Introduction Statistics Contact Development Disclaimer Help
tlbuf: optimize performing many single line changes - neatvi - [fork] simple vi…
git clone git://src.adamsgaard.dk/neatvi
Log
Files
Refs
README
---
commit cb01fab3ac9abd167109a9d1a6ac1211aaeaf873
parent 1f5e321f1f46b3e29f0b99015c2dd76a4b790e9b
Author: Ali Gholami Rudi <[email protected]>
Date: Wed, 15 Sep 2021 18:26:04 +0430
lbuf: optimize performing many single line changes
Reported by Kyryl Melekhin <[email protected]>.
Diffstat:
M lbuf.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
---
diff --git a/lbuf.c b/lbuf.c
t@@ -136,7 +136,7 @@ static void lbuf_replace(struct lbuf *lb, char *s, int pos…
int n_ins = linecount(s);
int i;
while (lb->ln_n + n_ins - n_del >= lb->ln_sz) {
- int nsz = lb->ln_sz + 512;
+ int nsz = lb->ln_sz + (lb->ln_sz ? lb->ln_sz : 512);
char **nln = malloc(nsz * sizeof(nln[0]));
char *nln_glob = malloc(nsz * sizeof(nln_glob[0]));
memcpy(nln, lb->ln, lb->ln_n * sizeof(lb->ln[0]));
t@@ -149,10 +149,12 @@ static void lbuf_replace(struct lbuf *lb, char *s, int p…
}
for (i = 0; i < n_del; i++)
free(lb->ln[pos + i]);
- memmove(lb->ln + pos + n_ins, lb->ln + pos + n_del,
- (lb->ln_n - pos - n_del) * sizeof(lb->ln[0]));
- memmove(lb->ln_glob + pos + n_ins, lb->ln_glob + pos + n_del,
- (lb->ln_n - pos - n_del) * sizeof(lb->ln_glob[0]));
+ if (n_ins != n_del) {
+ memmove(lb->ln + pos + n_ins, lb->ln + pos + n_del,
+ (lb->ln_n - pos - n_del) * sizeof(lb->ln[0]));
+ memmove(lb->ln_glob + pos + n_ins, lb->ln_glob + pos + n_del,
+ (lb->ln_n - pos - n_del) * sizeof(lb->ln_glob[0]));
+ }
lb->ln_n += n_ins - n_del;
for (i = 0; i < n_ins; i++) {
int l = s ? linelength(s) : 0;
t@@ -187,7 +189,7 @@ static void lbuf_opt(struct lbuf *lb, char *buf, int pos, …
lopt_done(&lb->hist[i]);
lb->hist_n = lb->hist_u;
if (lb->hist_n == lb->hist_sz) {
- int sz = lb->hist_sz + 128;
+ int sz = lb->hist_sz + (lb->hist_sz ? lb->hist_sz : 128);
struct lopt *hist = malloc(sz * sizeof(hist[0]));
memcpy(hist, lb->hist, lb->hist_n * sizeof(hist[0]));
free(lb->hist);
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.