From e39bba1a8a2fda74bcfd06f728b7e1fddadef161 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sun, 20 Feb 2022 15:26:23 -0500 Subject: Move mbs out of struct Edit, use a global buffer This saves 4K in the edit buffers, not to mention all the heap allocations for the separate mbs buffers! There might be a way to be more clever about capacities, but I don't think it's worth it. --- input.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 28349f4..a74335e 100644 --- a/input.c +++ b/input.c @@ -158,10 +158,15 @@ static char *inputStop( return stop; } +static size_t cap; +static char *buf; + void inputUpdate(void) { uint id = windowID(); - char *buf = editString(&edits[id]); - if (!buf) err(EX_OSERR, "editString"); + + size_t pos = 0; + const char *ptr = editString(&edits[id], &buf, &cap, &pos); + if (!ptr) err(EX_OSERR, "editString"); const char *prefix = ""; const char *prompt = self.nick; @@ -192,7 +197,7 @@ void inputUpdate(void) { } else { prompt = ""; } - if (skip > &buf[edits[id].mbs.pos]) { + if (skip > &buf[pos]) { prefix = prompt = suffix = ""; skip = buf; } @@ -209,14 +214,14 @@ void inputUpdate(void) { waddstr(uiInput, suffix); getyx(uiInput, y, x); - int pos; + int posx; struct Style style = styleInput; - inputStop(styleInput, &style, skip, &buf[edits[id].mbs.pos]); - getyx(uiInput, y, pos); + inputStop(styleInput, &style, skip, &buf[pos]); + getyx(uiInput, y, posx); wmove(uiInput, y, x); + ptr = skip; style = styleInput; - const char *ptr = skip; if (split) { ptr = inputStop(styleInput, &style, ptr, &buf[split]); style = styleInput; @@ -224,7 +229,7 @@ void inputUpdate(void) { } inputAdd(styleInput, &style, ptr); wclrtoeol(uiInput); - wmove(uiInput, y, pos); + wmove(uiInput, y, posx); } bool inputPending(uint id) { @@ -381,7 +386,7 @@ fail: static void inputEnter(void) { uint id = windowID(); - char *cmd = editString(&edits[id]); + char *cmd = editString(&edits[id], &buf, &cap, NULL); if (!cmd) err(EX_OSERR, "editString"); tabAccept(); @@ -459,8 +464,8 @@ static void keyCtrl(wchar_t ch) { break; case L'L': clearok(curscr, true); break; case L'N': windowShow(windowNum() + 1); break; case L'P': windowShow(windowNum() - 1); - break; case L'R': windowSearch(editString(edit), -1); - break; case L'S': windowSearch(editString(edit), +1); + break; case L'R': windowSearch(editString(edit, &buf, &cap, NULL), -1); + break; case L'S': windowSearch(editString(edit, &buf, &cap, NULL), +1); break; case L'T': error = editFn(edit, EditTranspose); break; case L'U': error = editFn(edit, EditDeleteHead); break; case L'V': windowScroll(ScrollPage, -1); -- cgit 1.4.1-2-gfad0