diff options
author | Pieter Noordhuis <pcnoordhuis@gmail.com> | 2011-01-19 18:01:01 +0100 |
---|---|---|
committer | Pieter Noordhuis <pcnoordhuis@gmail.com> | 2011-01-19 18:01:01 +0100 |
commit | f6a501001c18867d08b2ce222d177b8cf6c62a3a (patch) | |
tree | a1a6a664dfea8920a61d6dfb1783f027806f5eaf | |
parent | 5962a2de17b274a9313e87f33fbc7ba17d1dbd83 (diff) |
Discard consumed part of buffer less often
-rw-r--r-- | hiredis.c | 13 |
1 files changed, 4 insertions, 9 deletions
@@ -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); } |