From: Benno Schulenberg Date: Mon, 22 Feb 2016 14:26:05 +0000 (+0000) Subject: Eliding a variable -- there is no need to optimize for calls of strlen(), X-Git-Tag: v2.5.3~17 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=3ed08c568fddc1eff5fb296c4f90624153e4ac45;p=nano.git Eliding a variable -- there is no need to optimize for calls of strlen(), as this is typing speed, no need to hurry. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5663 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 0a1c5b67..cf0ff8b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ src/move.c (do_prev_word, do_next_word): Sort these in standard way. * src/prompt.c (do_statusbar_output): Don't move too many bytes. This fixes Savannah bug #47219 (uncovered by r5655). + * src/prompt.c (do_statusbar_output): Elide a variable. 2016-02-21 Benno Schulenberg * src/files.c (input_tab): If the first Tab added the part that all diff --git a/src/prompt.c b/src/prompt.c index 55855b6c..957c9db8 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -246,10 +246,9 @@ int do_statusbar_mouse(void) void do_statusbar_output(int *the_input, size_t input_len, bool filtering, bool *got_enter) { - size_t answer_len, i; char *output = charalloc(input_len + 1); char *char_buf = charalloc(mb_cur_max()); - int char_buf_len; + int i, char_buf_len; assert(answer != NULL); @@ -258,7 +257,6 @@ void do_statusbar_output(int *the_input, size_t input_len, output[i] = (char)the_input[i]; output[i] = '\0'; - answer_len = strlen(answer); i = 0; while (i < input_len) { @@ -284,15 +282,13 @@ void do_statusbar_output(int *the_input, size_t input_len, if (filtering && is_ascii_cntrl_char(*(output + i - char_buf_len))) continue; - /* More dangerousness fun. =) */ - answer = charealloc(answer, answer_len + char_buf_len + 1); - - assert(statusbar_x <= answer_len); + assert(statusbar_x <= strlen(answer)); + /* Insert the typed character into the existing answer string. */ + answer = charealloc(answer, strlen(answer) + char_buf_len + 1); charmove(answer + statusbar_x + char_buf_len, answer + statusbar_x, - answer_len - statusbar_x + 1); + strlen(answer) - statusbar_x + 1); strncpy(answer + statusbar_x, char_buf, char_buf_len); - answer_len += char_buf_len; statusbar_x += char_buf_len; }