MCPcopy Create free account
hub / github.com/F-Stack/f-stack / _quicklistZiplistMerge

Function _quicklistZiplistMerge

app/redis-6.2.6/src/quicklist.c:718–746  ·  view source on GitHub ↗

Given two nodes, try to merge their ziplists. * * This helps us not have a quicklist with 3 element ziplists if * our fill factor can handle much higher levels. * * Note: 'a' must be to the LEFT of 'b'. * * After calling this function, both 'a' and 'b' should be considered * unusable. The return value from this function must be used * instead of re-using any of the quicklistNode input ar

Source from the content-addressed store, hash-verified

716 * Returns the input node picked to merge against or NULL if
717 * merging was not possible. */
718REDIS_STATIC quicklistNode *_quicklistZiplistMerge(quicklist *quicklist,
719 quicklistNode *a,
720 quicklistNode *b) {
721 D("Requested merge (a,b) (%u, %u)", a->count, b->count);
722
723 quicklistDecompressNode(a);
724 quicklistDecompressNode(b);
725 if ((ziplistMerge(&a->zl, &b->zl))) {
726 /* We merged ziplists! Now remove the unused quicklistNode. */
727 quicklistNode *keep = NULL, *nokeep = NULL;
728 if (!a->zl) {
729 nokeep = a;
730 keep = b;
731 } else if (!b->zl) {
732 nokeep = b;
733 keep = a;
734 }
735 keep->count = ziplistLen(keep->zl);
736 quicklistNodeUpdateSz(keep);
737
738 nokeep->count = 0;
739 __quicklistDelNode(quicklist, nokeep);
740 quicklistCompress(quicklist, keep);
741 return keep;
742 } else {
743 /* else, the merge returned NULL and nothing changed. */
744 return NULL;
745 }
746}
747
748/* Attempt to merge ziplists within two nodes on either side of 'center'.
749 *

Callers 1

_quicklistMergeNodesFunction · 0.85

Calls 3

ziplistMergeFunction · 0.85
ziplistLenFunction · 0.85
__quicklistDelNodeFunction · 0.85

Tested by

no test coverage detected