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 */
| 275 | * |
| 276 | * The resulting object always has refcount set to 1 */ |
| 277 | robj *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 | |
| 308 | void saddCommand(client *c) { |
| 309 | robj *set; |
no test coverage detected