Skip to content

Commit

Permalink
Simplify rdbSaveLzfStringObject and move LZF_STATIC_BUFFER_SIZE to rdb.c
Browse files Browse the repository at this point in the history
  • Loading branch information
poiuj committed Nov 24, 2024
1 parent e2c17ac commit 6005959
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
11 changes: 5 additions & 6 deletions src/rdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
#include <sys/stat.h>
#include <sys/param.h>

/* Size of the static buffer used for rdbcompression */
#define LZF_STATIC_BUFFER_SIZE (8 * 1024)

/* This macro is called when the internal RDB structure is corrupt */
#define rdbReportCorruptRDB(...) rdbReportError(1, __LINE__, __VA_ARGS__)
/* This macro is called when RDB read failed (possibly a short read) */
Expand Down Expand Up @@ -400,12 +403,8 @@ ssize_t rdbSaveLzfStringObject(rio *rdb, unsigned char *s, size_t len) {
if ((out = zmalloc(outlen + 1)) == NULL) return 0;
}
comprlen = lzf_compress(s, len, out, outlen);
if (comprlen == 0) {
if (outlen >= LZF_STATIC_BUFFER_SIZE) zfree(out);
return 0;
}
ssize_t nwritten = rdbSaveLzfBlob(rdb, out, comprlen, len);
if (outlen >= LZF_STATIC_BUFFER_SIZE) zfree(out);
ssize_t nwritten = comprlen ? rdbSaveLzfBlob(rdb, out, comprlen, len) : 0;
if (out != buffer) zfree(out);
return nwritten;
}

Expand Down
3 changes: 0 additions & 3 deletions src/rdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@
#define RDB_LOAD_ERR_EMPTY_KEY 1 /* Error of empty key */
#define RDB_LOAD_ERR_OTHER 2 /* Any other errors */

/* Size of the static buffer used for rdbcompression */
#define LZF_STATIC_BUFFER_SIZE (8 * 1024)

ssize_t rdbWriteRaw(rio *rdb, void *p, size_t len);
int rdbSaveType(rio *rdb, unsigned char type);
int rdbLoadType(rio *rdb);
Expand Down

0 comments on commit 6005959

Please sign in to comment.