summaryrefslogtreecommitdiff
path: root/src/sds.c
diff options
context:
space:
mode:
authorSalvatore Sanfilippo <antirez@gmail.com>2018-02-27 04:04:32 -0800
committerGitHub <noreply@github.com>2018-02-27 04:04:32 -0800
commitd8830200b48b7f0b050e56f0c4e570311bcf7e3e (patch)
treefcac8c4349e5bd25676f97bfe8f1b21f0fc95a8e /src/sds.c
parent813960dbdd86b88b509b2946dbaa023e0ae8b1b9 (diff)
parentf86df924b01db43eb68f5c4b4cac4c44c1507390 (diff)
downloadredis-d8830200b48b7f0b050e56f0c4e570311bcf7e3e.tar.gz
Merge pull request #3828 from oranagra/sdsnewlen_pr
add SDS_NOINIT option to sdsnewlen to avoid unnecessary memsets.
Diffstat (limited to 'src/sds.c')
-rw-r--r--src/sds.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/sds.c b/src/sds.c
index 603e36aa1..1c977e450 100644
--- a/src/sds.c
+++ b/src/sds.c
@@ -39,6 +39,8 @@
#include "sds.h"
#include "sdsalloc.h"
+const char *SDS_NOINIT = "SDS_NOINIT";
+
static inline int sdsHdrSize(char type) {
switch(type&SDS_TYPE_MASK) {
case SDS_TYPE_5:
@@ -72,6 +74,7 @@ static inline char sdsReqType(size_t string_size) {
/* Create a new sds string with the content specified by the 'init' pointer
* and 'initlen'.
* If NULL is used for 'init' the string is initialized with zero bytes.
+ * If SDS_NOINIT is used, the buffer is left uninitialized;
*
* The string is always null-termined (all the sds strings are, always) so
* even if you create an sds string with:
@@ -92,7 +95,9 @@ sds sdsnewlen(const void *init, size_t initlen) {
unsigned char *fp; /* flags pointer. */
sh = s_malloc(hdrlen+initlen+1);
- if (!init)
+ if (init==SDS_NOINIT)
+ init = NULL;
+ else if (!init)
memset(sh, 0, hdrlen+initlen+1);
if (sh == NULL) return NULL;
s = (char*)sh+hdrlen;