Add a 24bit integer to ziplists to save one byte for ints that can
fit in 24 bits (thanks to antirez for catching and solving the two's compliment bug). Increment REDIS_RDB_VERSION to 6
This commit is contained in:
parent
21661d7acc
commit
5a86ab4799
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
/* The current RDB version. When the format changes in a way that is no longer
|
/* The current RDB version. When the format changes in a way that is no longer
|
||||||
* backward compatible this number gets incremented. */
|
* backward compatible this number gets incremented. */
|
||||||
#define REDIS_RDB_VERSION 5
|
#define REDIS_RDB_VERSION 6
|
||||||
|
|
||||||
/* Defines related to the dump file format. To store 32 bits lengths for short
|
/* Defines related to the dump file format. To store 32 bits lengths for short
|
||||||
* keys requires a lot of space, so we check the most significant 2 bits of
|
* keys requires a lot of space, so we check the most significant 2 bits of
|
||||||
|
@ -83,6 +83,10 @@
|
|||||||
#define ZIP_INT_16B (0xc0 | 0<<4)
|
#define ZIP_INT_16B (0xc0 | 0<<4)
|
||||||
#define ZIP_INT_32B (0xc0 | 1<<4)
|
#define ZIP_INT_32B (0xc0 | 1<<4)
|
||||||
#define ZIP_INT_64B (0xc0 | 2<<4)
|
#define ZIP_INT_64B (0xc0 | 2<<4)
|
||||||
|
#define ZIP_INT_24B (0xc0 | 3<<4)
|
||||||
|
|
||||||
|
#define INT24_MAX 0x7fffff
|
||||||
|
#define INT24_MIN (-INT24_MAX - 1)
|
||||||
|
|
||||||
/* Macro to determine type */
|
/* Macro to determine type */
|
||||||
#define ZIP_IS_STR(enc) (((enc) & ZIP_STR_MASK) < ZIP_STR_MASK)
|
#define ZIP_IS_STR(enc) (((enc) & ZIP_STR_MASK) < ZIP_STR_MASK)
|
||||||
@ -123,6 +127,7 @@ typedef struct zlentry {
|
|||||||
static unsigned int zipIntSize(unsigned char encoding) {
|
static unsigned int zipIntSize(unsigned char encoding) {
|
||||||
switch(encoding) {
|
switch(encoding) {
|
||||||
case ZIP_INT_16B: return sizeof(int16_t);
|
case ZIP_INT_16B: return sizeof(int16_t);
|
||||||
|
case ZIP_INT_24B: return sizeof(int32_t)-sizeof(int8_t);
|
||||||
case ZIP_INT_32B: return sizeof(int32_t);
|
case ZIP_INT_32B: return sizeof(int32_t);
|
||||||
case ZIP_INT_64B: return sizeof(int64_t);
|
case ZIP_INT_64B: return sizeof(int64_t);
|
||||||
}
|
}
|
||||||
@ -271,6 +276,8 @@ static int zipTryEncoding(unsigned char *entry, unsigned int entrylen, long long
|
|||||||
* of our encoding types that can hold this value. */
|
* of our encoding types that can hold this value. */
|
||||||
if (value >= INT16_MIN && value <= INT16_MAX) {
|
if (value >= INT16_MIN && value <= INT16_MAX) {
|
||||||
*encoding = ZIP_INT_16B;
|
*encoding = ZIP_INT_16B;
|
||||||
|
} else if (value >= INT24_MIN && value <= INT24_MAX) {
|
||||||
|
*encoding = ZIP_INT_24B;
|
||||||
} else if (value >= INT32_MIN && value <= INT32_MAX) {
|
} else if (value >= INT32_MIN && value <= INT32_MAX) {
|
||||||
*encoding = ZIP_INT_32B;
|
*encoding = ZIP_INT_32B;
|
||||||
} else {
|
} else {
|
||||||
@ -291,6 +298,10 @@ static void zipSaveInteger(unsigned char *p, int64_t value, unsigned char encodi
|
|||||||
i16 = value;
|
i16 = value;
|
||||||
memcpy(p,&i16,sizeof(i16));
|
memcpy(p,&i16,sizeof(i16));
|
||||||
memrev16ifbe(p);
|
memrev16ifbe(p);
|
||||||
|
} else if (encoding == ZIP_INT_24B) {
|
||||||
|
i32 = value<<8;
|
||||||
|
memrev32ifbe(&i32);
|
||||||
|
memcpy(p,((unsigned char*)&i32)+1,sizeof(i32)-sizeof(int8_t));
|
||||||
} else if (encoding == ZIP_INT_32B) {
|
} else if (encoding == ZIP_INT_32B) {
|
||||||
i32 = value;
|
i32 = value;
|
||||||
memcpy(p,&i32,sizeof(i32));
|
memcpy(p,&i32,sizeof(i32));
|
||||||
@ -317,6 +328,11 @@ static int64_t zipLoadInteger(unsigned char *p, unsigned char encoding) {
|
|||||||
memcpy(&i32,p,sizeof(i32));
|
memcpy(&i32,p,sizeof(i32));
|
||||||
memrev32ifbe(&i32);
|
memrev32ifbe(&i32);
|
||||||
ret = i32;
|
ret = i32;
|
||||||
|
} else if (encoding == ZIP_INT_24B) {
|
||||||
|
i32 = 0;
|
||||||
|
memcpy(((unsigned char*)&i32)+1,p,sizeof(i32)-sizeof(int8_t));
|
||||||
|
memrev32ifbe(&i32);
|
||||||
|
ret = i32>>8;
|
||||||
} else if (encoding == ZIP_INT_64B) {
|
} else if (encoding == ZIP_INT_64B) {
|
||||||
memcpy(&i64,p,sizeof(i64));
|
memcpy(&i64,p,sizeof(i64));
|
||||||
memrev64ifbe(&i64);
|
memrev64ifbe(&i64);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user