From b6bd7fcaa6549a7b9dac4410a2c5bc01035c2b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Fri, 12 Jul 2013 20:27:31 +0200 Subject: [PATCH] Don't memmove the buffer content unless it's needed --- src/dbuf.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/dbuf.c b/src/dbuf.c index 8cf6c80..c5cd1ce 100644 --- a/src/dbuf.c +++ b/src/dbuf.c @@ -50,7 +50,10 @@ uc_dbuf_ensure(DBuf *buf, size_t capacity) return 0; len = uc_dbuf_len(buf); sz = buf->start - buf->bufstart; - memmove(buf->bufstart, buf->start, len); + + if (buf->bufstart != buf->start) + memmove(buf->bufstart, buf->start, len); + if (sz + remaining < capacity) { size_t newlen = uc_dbuf_buflen(buf) + capacity; void *tmp = realloc(buf->bufstart, newlen); @@ -75,7 +78,8 @@ uc_dbuf_trim(DBuf *buf) if (len == 0) return; - memmove(buf->bufstart, buf->start, len); + if (buf->bufstart != buf->start) + memmove(buf->bufstart, buf->start, len); tmp = realloc(buf->bufstart, len); if (tmp != NULL)