nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 68ca1732b8eecb1112ff0635560ad67b00844deb
parent 75f4309c1fd8ea24c6c217d0a792e1c2e81d7b49
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Thu, 13 Feb 2020 14:42:47 +0100

prompt: insert a burst of bytes in one go instead of characterwise

There is no need to count characters, so just insert the whole batch
of bytes at once.

Diffstat:
Msrc/prompt.c | 19++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/src/prompt.c b/src/prompt.c @@ -176,24 +176,17 @@ int do_statusbar_input(bool *finished) /* Insert the given short burst of bytes into the anwer. */ void inject_into_answer(char *burst, size_t count) { - size_t charlen, index = 0; - - while (index < count) { - /* Encode any NUL byte as 0x0A. */ + /* First encode any embedded NUL byte as 0x0A. */ + for (size_t index = 0; index < count; index++) if (burst[index] == '\0') burst[index] = '\n'; - charlen = char_length(burst + index); - - /* Insert the typed character into the existing answer string. */ - answer = charealloc(answer, strlen(answer) + charlen + 1); - memmove(answer + typing_x + charlen, answer + typing_x, + answer = charealloc(answer, strlen(answer) + count + 1); + memmove(answer + typing_x + count, answer + typing_x, strlen(answer) - typing_x + 1); - strncpy(answer + typing_x, burst + index, charlen); + strncpy(answer + typing_x, burst , count); - typing_x += charlen; - index += charlen; - } + typing_x += count; } /* Move to the beginning of the answer. */