summary refs log tree commit diff
path: root/input.c
diff options
context:
space:
mode:
authorJune McEnroe2022-02-20 15:26:23 -0500
committerJune McEnroe2022-02-20 15:42:24 -0500
commite39bba1a8a2fda74bcfd06f728b7e1fddadef161 (patch)
tree2add7aeaba4d0c69116c2f672d05e407fbffcdb3 /input.c
parentcca9688cca171dc3ee6ac24822bdd8c315997759 (diff)
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.
Diffstat (limited to 'input.c')
-rw-r--r--input.c27
1 files changed, 16 insertions, 11 deletions
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);