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

Function replaceSatelliteDictKeyPtrAndOrDefragDictEntry

src/defrag.cpp:411–425  ·  view source on GitHub ↗

Utility function that replaces an old key pointer in the dictionary with a * new pointer. Additionally, we try to defrag the dictEntry in that dict. * Oldkey mey be a dead pointer and should not be accessed (we get a * pre-calculated hash value). Newkey may be null if the key pointer wasn't * moved. Return value is the the dictEntry if found, or NULL if not found. * NOTE: this is very ugly co

Source from the content-addressed store, hash-verified

409 * NOTE: this is very ugly code, but it let's us avoid the complication of
410 * doing a scan on another dict. */
411dictEntry* replaceSatelliteDictKeyPtrAndOrDefragDictEntry(dict *d, sds oldkey, sds newkey, uint64_t hash, long *defragged) {
412 dictEntry **deref = dictFindEntryRefByPtrAndHash(d, oldkey, hash);
413 if (deref) {
414 dictEntry *de = *deref;
415 dictEntry *newde = (dictEntry*)activeDefragAlloc(de);
416 if (newde) {
417 de = *deref = newde;
418 (*defragged)++;
419 }
420 if (newkey)
421 de->key = newkey;
422 return de;
423 }
424 return NULL;
425}
426
427long activeDefragQuickListNode(quicklist *ql, quicklistNode **node_ref) {
428 quicklistNode *newnode, *node = *node_ref;

Callers

nothing calls this directly

Calls 2

activeDefragAllocFunction · 0.85

Tested by

no test coverage detected