summaryrefslogtreecommitdiff
path: root/src/listpack.h
diff options
context:
space:
mode:
authoryihuang <huang@crypto.com>2021-02-16 22:17:38 +0800
committerGitHub <noreply@github.com>2021-02-16 16:17:38 +0200
commitaab479f8cfaa4493f5618ba05cfec0e2b406e77c (patch)
tree1ee813e107dc086911e7b3066a3e1a51f09a0b35 /src/listpack.h
parentfd052d2a86b1a9ace29abf2868785f0b4621b715 (diff)
downloadredis-aab479f8cfaa4493f5618ba05cfec0e2b406e77c.tar.gz
Optimize listpack for stream usage to avoid repeated reallocs (#6281)
Avoid repeated reallocs growing the listpack while entries are being added. This is done by pre-allocating the listpack to near maximum size, and using malloc_size to check if it needs realloc or not. When the listpack reaches the maximum number of entries, we shrink it to fit it's used size. Co-authored-by: Viktor Söderqvist <viktor@zuiderkwast.se> Co-authored-by: Oran Agra <oran@redislabs.com>
Diffstat (limited to 'src/listpack.h')
-rw-r--r--src/listpack.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/listpack.h b/src/listpack.h
index e8375628b..f87622c18 100644
--- a/src/listpack.h
+++ b/src/listpack.h
@@ -35,6 +35,7 @@
#ifndef __LISTPACK_H
#define __LISTPACK_H
+#include <stdlib.h>
#include <stdint.h>
#define LP_INTBUF_SIZE 21 /* 20 digits of -2^63 + 1 null term = 21. */
@@ -44,8 +45,9 @@
#define LP_AFTER 1
#define LP_REPLACE 2
-unsigned char *lpNew(void);
+unsigned char *lpNew(size_t capacity);
void lpFree(unsigned char *lp);
+unsigned char* lpShrinkToFit(unsigned char *lp);
unsigned char *lpInsert(unsigned char *lp, unsigned char *ele, uint32_t size, unsigned char *p, int where, unsigned char **newp);
unsigned char *lpAppend(unsigned char *lp, unsigned char *ele, uint32_t size);
unsigned char *lpDelete(unsigned char *lp, unsigned char *p, unsigned char **newp);