diff options
author | Salvatore Sanfilippo <antirez@gmail.com> | 2018-02-27 04:04:32 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-27 04:04:32 -0800 |
commit | d8830200b48b7f0b050e56f0c4e570311bcf7e3e (patch) | |
tree | fcac8c4349e5bd25676f97bfe8f1b21f0fc95a8e /src/sds.c | |
parent | 813960dbdd86b88b509b2946dbaa023e0ae8b1b9 (diff) | |
parent | f86df924b01db43eb68f5c4b4cac4c44c1507390 (diff) | |
download | redis-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.c | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -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; |