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

Function _quicklistNodeAllowInsert

src/quicklist.c:428–460  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

426#define sizeMeetsSafetyLimit(sz) ((sz) <= SIZE_SAFETY_LIMIT)
427
428REDIS_STATIC int _quicklistNodeAllowInsert(const quicklistNode *node,
429 const int fill, const size_t sz) {
430 if (unlikely(!node))
431 return 0;
432
433 int ziplist_overhead;
434 /* size of previous offset */
435 if (sz < 254)
436 ziplist_overhead = 1;
437 else
438 ziplist_overhead = 5;
439
440 /* size of forward offset */
441 if (sz < 64)
442 ziplist_overhead += 1;
443 else if (likely(sz < 16384))
444 ziplist_overhead += 2;
445 else
446 ziplist_overhead += 5;
447
448 /* new_sz overestimates if 'sz' encodes to an integer type */
449 unsigned int new_sz = node->sz + sz + ziplist_overhead;
450 if (likely(_quicklistNodeSizeMeetsOptimizationRequirement(new_sz, fill)))
451 return 1;
452 /* when we return 1 above we know that the limit is a size limit (which is
453 * safe, see comments next to optimization_level and SIZE_SAFETY_LIMIT) */
454 else if (!sizeMeetsSafetyLimit(new_sz))
455 return 0;
456 else if ((int)node->count < fill)
457 return 1;
458 else
459 return 0;
460}
461
462REDIS_STATIC int _quicklistNodeAllowMerge(const quicklistNode *a,
463 const quicklistNode *b,

Callers 3

quicklistPushHeadFunction · 0.85
quicklistPushTailFunction · 0.85
_quicklistInsertFunction · 0.85

Tested by

no test coverage detected