Don't memmove the buffer content unless it's needed
This commit is contained in:
@@ -50,7 +50,10 @@ uc_dbuf_ensure(DBuf *buf, size_t capacity)
|
|||||||
return 0;
|
return 0;
|
||||||
len = uc_dbuf_len(buf);
|
len = uc_dbuf_len(buf);
|
||||||
sz = buf->start - buf->bufstart;
|
sz = buf->start - buf->bufstart;
|
||||||
|
|
||||||
|
if (buf->bufstart != buf->start)
|
||||||
memmove(buf->bufstart, buf->start, len);
|
memmove(buf->bufstart, buf->start, len);
|
||||||
|
|
||||||
if (sz + remaining < capacity) {
|
if (sz + remaining < capacity) {
|
||||||
size_t newlen = uc_dbuf_buflen(buf) + capacity;
|
size_t newlen = uc_dbuf_buflen(buf) + capacity;
|
||||||
void *tmp = realloc(buf->bufstart, newlen);
|
void *tmp = realloc(buf->bufstart, newlen);
|
||||||
@@ -75,6 +78,7 @@ uc_dbuf_trim(DBuf *buf)
|
|||||||
if (len == 0)
|
if (len == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (buf->bufstart != buf->start)
|
||||||
memmove(buf->bufstart, buf->start, len);
|
memmove(buf->bufstart, buf->start, len);
|
||||||
|
|
||||||
tmp = realloc(buf->bufstart, len);
|
tmp = realloc(buf->bufstart, len);
|
||||||
|
|||||||
Reference in New Issue
Block a user