Code

wreadln: use memcpy() for both cases
authorMax Kellermann <max@duempel.org>
Mon, 6 Oct 2008 12:55:31 +0000 (14:55 +0200)
committerMax Kellermann <max@duempel.org>
Mon, 6 Oct 2008 12:55:31 +0000 (14:55 +0200)
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

index 0bfc414086a7ac541b990d776492a74f146576c0..5d019d9003d3438b1287141082fa380349dbf167 100644 (file)
@@ -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);
 }