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

Function setTypeDup

src/t_set.cpp:277–306  ·  view source on GitHub ↗

This is a helper function for the COPY command. * Duplicate a set object, with the guarantee that the returned object * has the same encoding as the original one. * * The resulting object always has refcount set to 1 */

Source from the content-addressed store, hash-verified

275 *
276 * The resulting object always has refcount set to 1 */
277robj *setTypeDup(robj *o) {
278 robj *set;
279 setTypeIterator *si;
280 const char *elesds;
281 int64_t intobj;
282
283 serverAssert(o->type == OBJ_SET);
284
285 /* Create a new set object that have the same encoding as the original object's encoding */
286 if (o->encoding == OBJ_ENCODING_INTSET) {
287 intset *is = (intset*)ptrFromObj(o);
288 size_t size = intsetBlobLen(is);
289 intset *newis = (intset*)zmalloc(size);
290 memcpy(newis,is,size);
291 set = createObject(OBJ_SET, newis);
292 set->encoding = OBJ_ENCODING_INTSET;
293 } else if (o->encoding == OBJ_ENCODING_HT) {
294 set = createSetObject();
295 dict *d = (dict*)ptrFromObj(o);
296 dictExpand((dict*)ptrFromObj(set), dictSize(d));
297 si = setTypeInitIterator(o);
298 while (setTypeNext(si, &elesds, &intobj) != -1) {
299 setTypeAdd(set, elesds);
300 }
301 setTypeReleaseIterator(si);
302 } else {
303 serverPanic("Unknown set encoding");
304 }
305 return set;
306}
307
308void saddCommand(client *c) {
309 robj *set;

Callers 1

copyCommandFunction · 0.85

Calls 10

ptrFromObjFunction · 0.85
intsetBlobLenFunction · 0.85
zmallocFunction · 0.85
createObjectFunction · 0.85
createSetObjectFunction · 0.85
setTypeInitIteratorFunction · 0.85
setTypeNextFunction · 0.85
setTypeAddFunction · 0.85
setTypeReleaseIteratorFunction · 0.85
dictExpandFunction · 0.70

Tested by

no test coverage detected