Merge pull request #178 from lightning-speed/patch-2
Replaced Multiple strlen(buffer) call with one call
This commit is contained in:
commit
dc3de36c7e
@ -412,6 +412,7 @@ refresh:
|
|||||||
term_double_buffer_flush();
|
term_double_buffer_flush();
|
||||||
|
|
||||||
int c = getchar();
|
int c = getchar();
|
||||||
|
size_t buffer_len = strlen(buffer);
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case GETCHAR_CURSOR_DOWN:
|
case GETCHAR_CURSOR_DOWN:
|
||||||
cursor_offset = get_next_line(cursor_offset, buffer);
|
cursor_offset = get_next_line(cursor_offset, buffer);
|
||||||
@ -425,7 +426,7 @@ refresh:
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GETCHAR_CURSOR_RIGHT:
|
case GETCHAR_CURSOR_RIGHT:
|
||||||
if (cursor_offset < strlen(buffer)) {
|
if (cursor_offset < buffer_len) {
|
||||||
cursor_offset++;
|
cursor_offset++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -458,9 +459,9 @@ refresh:
|
|||||||
editor_no_term_reset ? editor_no_term_reset = false : reset_term();
|
editor_no_term_reset ? editor_no_term_reset = false : reset_term();
|
||||||
return NULL;
|
return NULL;
|
||||||
default:
|
default:
|
||||||
if (strlen(buffer) < EDITOR_MAX_BUFFER_SIZE - 1) {
|
if (buffer_len < EDITOR_MAX_BUFFER_SIZE - 1) {
|
||||||
if (isprint(c) || c == '\n') {
|
if (isprint(c) || c == '\n') {
|
||||||
for (size_t i = strlen(buffer); ; i--) {
|
for (size_t i = buffer_len; ; i--) {
|
||||||
buffer[i+1] = buffer[i];
|
buffer[i+1] = buffer[i];
|
||||||
if (i == cursor_offset)
|
if (i == cursor_offset)
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user