Duplicate a string object, with the guarantee that the returned object * has the same encoding as the original one. * * This function also guarantees that duplicating a small integer object * (or a string object that contains a representation of a small integer) * will always result in a fresh object that is unshared (refcount == 1). * * The resulting object always has refcount set to 1. */
| 232 | * |
| 233 | * The resulting object always has refcount set to 1. */ |
| 234 | robj *dupStringObject(const robj *o) { |
| 235 | robj *d; |
| 236 | |
| 237 | serverAssert(o->type == OBJ_STRING); |
| 238 | |
| 239 | switch(o->encoding) { |
| 240 | case OBJ_ENCODING_RAW: |
| 241 | return createRawStringObject(szFromObj(o),sdslen(szFromObj(o))); |
| 242 | case OBJ_ENCODING_EMBSTR: |
| 243 | return createEmbeddedStringObject(szFromObj(o),sdslen(szFromObj(o))); |
| 244 | case OBJ_ENCODING_INT: |
| 245 | d = createObject(OBJ_STRING, NULL); |
| 246 | d->encoding = OBJ_ENCODING_INT; |
| 247 | d->m_ptr = ptrFromObj(o); |
| 248 | return d; |
| 249 | default: |
| 250 | serverPanic("Wrong encoding."); |
| 251 | break; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | robj *createQuicklistObject(void) { |
| 256 | quicklist *l = quicklistCreate(); |
no test coverage detected