From: Michael D. Lowis Date: Fri, 28 Oct 2016 16:36:41 +0000 (-0400) Subject: Implemented log coalescing for inserts X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=c98f97c33f8595118079a7e6a1de24b3048b3f31;p=projs%2Ftide.git Implemented log coalescing for inserts --- diff --git a/buf.c b/buf.c index 72020e1..f145b60 100644 --- a/buf.c +++ b/buf.c @@ -94,12 +94,24 @@ void buf_init(Buf* buf) { } static void log_insert(Log** list, unsigned beg, unsigned end) { - Log* newlog = (Log*)calloc(sizeof(Log), 1); - newlog->insert = true; - newlog->data.ins.beg = beg; - newlog->data.ins.end = end; - newlog->next = *list; - *list = newlog; + Log* log = *list; + if (!log || log->locked || !log->insert || (log->data.ins.beg && beg < log->data.ins.beg-1) || end > log->data.ins.end+1) { + //if (log) printf("%d %d %d %d\n", log->locked, !log->insert, beg < log->data.ins.beg-1, end > log->data.ins.end+1); + //if (log) printf("%u < %u\n", beg, log->data.ins.beg-1); + //printf("new %u-%u\n", beg, end); + Log* newlog = (Log*)calloc(sizeof(Log), 1); + newlog->insert = true; + newlog->data.ins.beg = beg; + newlog->data.ins.end = end; + newlog->next = *list; + *list = newlog; + } else if (beg <= log->data.ins.beg) { + //puts("coalesce 1"); + log->data.ins.beg--; + } else { + //puts("coalesce 2"); + log->data.ins.end++; + } } static void log_delete(Log** list, unsigned off, Rune* r, size_t len) {