MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / dupStringObject

Function dupStringObject

src/object.cpp:234–253  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

232 *
233 * The resulting object always has refcount set to 1. */
234robj *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
255robj *createQuicklistObject(void) {
256 quicklist *l = quicklistCreate();

Callers 6

dbOverwriteCoreMethod · 0.85
copyCommandFunction · 0.85
setExpireFunction · 0.85
setExpireMethod · 0.85
slowlogCreateEntryFunction · 0.85

Calls 6

createRawStringObjectFunction · 0.85
szFromObjFunction · 0.85
sdslenFunction · 0.85
createObjectFunction · 0.85
ptrFromObjFunction · 0.85

Tested by

no test coverage detected