remove unnecessary allocation in rdb save
Former-commit-id: dfa76f04fd862e0cc7b4d3284b3922e3a5e5549d
This commit is contained in:
parent
a14b2097c3
commit
2268a2b761
12
src/rdb.cpp
12
src/rdb.cpp
@ -349,20 +349,24 @@ writeerr:
|
||||
}
|
||||
|
||||
ssize_t rdbSaveLzfStringObject(rio *rdb, const unsigned char *s, size_t len) {
|
||||
char rgbuf[2048];
|
||||
size_t comprlen, outlen;
|
||||
void *out;
|
||||
void *out = rgbuf;
|
||||
|
||||
/* We require at least four bytes compression for this to be worth it */
|
||||
if (len <= 4) return 0;
|
||||
outlen = len-4;
|
||||
if ((out = zmalloc(outlen+1, MALLOC_LOCAL)) == NULL) return 0;
|
||||
if (outlen >= sizeof(rgbuf))
|
||||
if ((out = zmalloc(outlen+1, MALLOC_LOCAL)) == NULL) return 0;
|
||||
comprlen = lzf_compress(s, len, out, outlen);
|
||||
if (comprlen == 0) {
|
||||
zfree(out);
|
||||
if (out != rgbuf)
|
||||
zfree(out);
|
||||
return 0;
|
||||
}
|
||||
ssize_t nwritten = rdbSaveLzfBlob(rdb, out, comprlen, len);
|
||||
zfree(out);
|
||||
if (out != rgbuf)
|
||||
zfree(out);
|
||||
return nwritten;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user