From f6a501001c18867d08b2ce222d177b8cf6c62a3a Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Wed, 19 Jan 2011 18:01:01 +0100 Subject: Discard consumed part of buffer less often --- hiredis.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'hiredis.c') diff --git a/hiredis.c b/hiredis.c index ac6dc67..1751366 100644 --- a/hiredis.c +++ b/hiredis.c @@ -538,15 +538,10 @@ int redisReplyReaderGetReply(void *reader, void **reply) { if (processItem(r) < 0) break; - /* Discard the consumed part of the buffer. */ - if (r->pos > 0) { - if (r->pos == r->len) { - /* sdsrange has a quirck on this edge case. */ - sdsfree(r->buf); - r->buf = sdsempty(); - } else { - r->buf = sdsrange(r->buf,r->pos,r->len); - } + /* Discard part of the buffer when we've consumed at least 1k, to avoid + * doing unnecessary calls to memmove() in sds.c. */ + if (r->pos >= 1024) { + r->buf = sdsrange(r->buf,r->pos,r->len); r->pos = 0; r->len = sdslen(r->buf); } -- cgit v1.2.3