commit 067b0a336731abda0ccf926c48c508726bdd643f
parent 24b10179a149b4bf88886908018322f5a8753d86
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Sun, 26 Jun 2016 14:08:05 +0200
input: elide an extra buffer for inserting stuff into the text
Do the casting from integer to character rightaway in the first
intermediate buffer.
Diffstat:
1 file changed, 8 insertions(+), 16 deletions(-)
diff --git a/src/nano.c b/src/nano.c
@@ -1569,7 +1569,7 @@ int do_input(bool allow_funcs)
{
int input;
/* The keystroke we read in: a character or a shortcut. */
- static int *puddle = NULL;
+ static char *puddle = NULL;
/* The input buffer for actual characters. */
static size_t depth = 0;
/* The length of the input buffer. */
@@ -1625,9 +1625,9 @@ int do_input(bool allow_funcs)
if (ISSET(VIEW_MODE))
print_view_warning();
else {
- depth++;
- puddle = (int *)nrealloc(puddle, depth * sizeof(int));
- puddle[depth - 1] = input;
+ /* Store the byte, and leave room for a terminating zero. */
+ puddle = charealloc(puddle, depth + 2);
+ puddle[depth++] = (char)input;
}
}
@@ -1644,18 +1644,10 @@ int do_input(bool allow_funcs)
#endif
if (puddle != NULL) {
- /* Display all the characters in the input buffer at
- * once, filtering out control characters. */
- char *output = charalloc(depth + 1);
- size_t i;
-
- for (i = 0; i < depth; i++)
- output[i] = (char)puddle[i];
- output[i] = '\0';
-
- do_output(output, depth, FALSE);
-
- free(output);
+ /* Insert all bytes in the input buffer into the edit buffer
+ * at once, filtering out any low control codes. */
+ puddle[depth] = '\0';
+ do_output(puddle, depth, FALSE);
/* Empty the input buffer. */
free(puddle);