From 003f90586c1eab5f17cdc85bf0fc43e5f2a170ec Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 6 Oct 2008 14:56:18 +0200 Subject: wreadln: optimize wreadln_delete_char() with memmove() Let memmove() do the dirty work on overlapping buffers.. --- src/wreadln.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/wreadln.c') diff --git a/src/wreadln.c b/src/wreadln.c index 608141f64..89bcc123c 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 */ -- cgit v1.2.3