From: Max Kellermann Date: Mon, 6 Oct 2008 12:56:18 +0000 (+0200) Subject: wreadln: optimize wreadln_delete_char() with memmove() X-Git-Tag: v0.12_alpha1~52 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=003f90586c1eab5f17cdc85bf0fc43e5f2a170ec;p=ncmpc.git wreadln: optimize wreadln_delete_char() with memmove() Let memmove() do the dirty work on overlapping buffers.. --- diff --git a/src/wreadln.c b/src/wreadln.c index 608141f..89bcc12 100644 --- a/src/wreadln.c +++ b/src/wreadln.c @@ -136,12 +136,13 @@ wreadln_insert_byte(struct wreadln *wr, gint key) static void wreadln_delete_char(struct wreadln *wr, size_t x) { - size_t i; + size_t rest; + const size_t length = 1; assert(x < strlen(wr->line)); - for (i = x; wr->line[i] != 0; i++) - wr->line[i] = wr->line[i + 1]; + rest = strlen(&wr->line[x + length]) + 1; + memmove(&wr->line[x], &wr->line[x + length], rest); } /* libcurses version */