diff options
author | antirez <antirez@gmail.com> | 2014-03-30 18:32:17 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2014-03-30 18:32:17 +0200 |
commit | 543ede03f2e54b45b22164e17c7f51de9cfc69fa (patch) | |
tree | 19c4beb012a814620ad90f5416915ba640638304 /src/bitops.c | |
parent | aaf6db459b34dc2182fe1d84596733a9b9e97ec4 (diff) | |
download | redis-543ede03f2e54b45b22164e17c7f51de9cfc69fa.tar.gz |
String value unsharing refactored into proper function.
All the Redis functions that need to modify the string value of a key in
a destructive way (APPEND, SETBIT, SETRANGE, ...) require to make the
object unshared (if refcount > 1) and encoded in raw format (if encoding
is not already REDIS_ENCODING_RAW).
This was cut & pasted many times in multiple places of the code. This
commit puts the small logic needed into a function called
dbUnshareStringValue().
Diffstat (limited to 'src/bitops.c')
-rw-r--r-- | src/bitops.c | 9 |
1 files changed, 1 insertions, 8 deletions
diff --git a/src/bitops.c b/src/bitops.c index 6cf02dc13..28f772430 100644 --- a/src/bitops.c +++ b/src/bitops.c @@ -223,14 +223,7 @@ void setbitCommand(redisClient *c) { dbAdd(c->db,c->argv[1],o); } else { if (checkType(c,o,REDIS_STRING)) return; - - /* Create a copy when the object is shared or encoded. */ - if (o->refcount != 1 || o->encoding != REDIS_ENCODING_RAW) { - robj *decoded = getDecodedObject(o); - o = createRawStringObject(decoded->ptr, sdslen(decoded->ptr)); - decrRefCount(decoded); - dbOverwrite(c->db,c->argv[1],o); - } + o = dbUnshareStringValue(c->db,c->argv[1],o); } /* Grow sds value to the right length if necessary */ |