From 3a92aa17478c901b1704fb935723783b11f193e7 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 6 Oct 2008 14:55:31 +0200 Subject: [PATCH] wreadln: use memcpy() for both cases Use memcpy() even when the cursor is at the end. It copies only the trailing null terminator in this case. The constant "length" is declared here in preparation for the "wide character" patches. --- src/wreadln.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/wreadln.c b/src/wreadln.c index 0bfc414..5d019d9 100644 --- a/src/wreadln.c +++ b/src/wreadln.c @@ -120,17 +120,12 @@ static inline void drawline(const struct wreadln *wr) static void wreadln_insert_byte(struct wreadln *wr, gint key) { - if (strlen(wr->line + wr->cursor)) { /* if the cursor is */ - /* not at the last pos */ - gsize rest = strlen(wr->line + wr->cursor) + 1; - - memmove(wr->line + wr->cursor + 1, - wr->line + wr->cursor, rest); - wr->line[wr->cursor] = key; - } else { - wr->line[wr->cursor + 1] = 0; - wr->line[wr->cursor] = key; - } + size_t rest = strlen(wr->line + wr->cursor) + 1; + const size_t length = 1; + + memmove(wr->line + wr->cursor + length, + wr->line + wr->cursor, rest); + wr->line[wr->cursor] = key; cursor_move_right(wr); } -- 2.30.2