Commit 9454f7b3 authored by Salvatore Sanfilippo's avatar Salvatore Sanfilippo
Browse files

Merge pull request #2050 from mattsta/bitops-no-overalloc

Bitops: Stop overallocating storage space on set
parents e00cb78f badf0f00
...@@ -229,18 +229,16 @@ void setbitCommand(redisClient *c) { ...@@ -229,18 +229,16 @@ void setbitCommand(redisClient *c) {
return; return;
} }
byte = bitoffset >> 3;
o = lookupKeyWrite(c->db,c->argv[1]); o = lookupKeyWrite(c->db,c->argv[1]);
if (o == NULL) { if (o == NULL) {
o = createObject(REDIS_STRING,sdsempty()); o = createObject(REDIS_STRING,sdsnewlen(NULL, byte+1));
dbAdd(c->db,c->argv[1],o); dbAdd(c->db,c->argv[1],o);
} else { } else {
if (checkType(c,o,REDIS_STRING)) return; if (checkType(c,o,REDIS_STRING)) return;
o = dbUnshareStringValue(c->db,c->argv[1],o); o = dbUnshareStringValue(c->db,c->argv[1],o);
}
/* Grow sds value to the right length if necessary */
byte = bitoffset >> 3;
o->ptr = sdsgrowzero(o->ptr,byte+1); o->ptr = sdsgrowzero(o->ptr,byte+1);
}
/* Get current values */ /* Get current values */
byteval = ((uint8_t*)o->ptr)[byte]; byteval = ((uint8_t*)o->ptr)[byte];
......
...@@ -206,7 +206,7 @@ void setrangeCommand(redisClient *c) { ...@@ -206,7 +206,7 @@ void setrangeCommand(redisClient *c) {
if (checkStringLength(c,offset+sdslen(value)) != REDIS_OK) if (checkStringLength(c,offset+sdslen(value)) != REDIS_OK)
return; return;
o = createObject(REDIS_STRING,sdsempty()); o = createObject(REDIS_STRING,sdsnewlen(NULL, offset+sdslen(value)));
dbAdd(c->db,c->argv[1],o); dbAdd(c->db,c->argv[1],o);
} else { } else {
size_t olen; size_t olen;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment