summaryrefslogtreecommitdiff
path: root/hiredis.c
diff options
context:
space:
mode:
authorPieter Noordhuis <pcnoordhuis@gmail.com>2011-01-19 18:01:01 +0100
committerPieter Noordhuis <pcnoordhuis@gmail.com>2011-01-19 18:01:01 +0100
commitf6a501001c18867d08b2ce222d177b8cf6c62a3a (patch)
treea1a6a664dfea8920a61d6dfb1783f027806f5eaf /hiredis.c
parent5962a2de17b274a9313e87f33fbc7ba17d1dbd83 (diff)
Discard consumed part of buffer less often
Diffstat (limited to 'hiredis.c')
-rw-r--r--hiredis.c13
1 files changed, 4 insertions, 9 deletions
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);
}