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

Function quicklistPopCustom

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

pop from quicklist and return result in 'data' ptr. Value of 'data' * is the return value of 'saver' function pointer if the data is NOT a number. * * If the quicklist element is a long long, then the return value is returned in * 'sval'. * * Return value of 0 means no elements available. * Return value of 1 means check 'data' and 'sval' for values. * If 'data' is set, use 'data' and 'sz'

Source from the content-addressed store, hash-verified

1356 * Return value of 1 means check 'data' and 'sval' for values.
1357 * If 'data' is set, use 'data' and 'sz'. Otherwise, use 'sval'. */
1358int quicklistPopCustom(quicklist *quicklist, int where, unsigned char **data,
1359 unsigned int *sz, long long *sval,
1360 void *(*saver)(unsigned char *data, unsigned int sz)) {
1361 unsigned char *p;
1362 unsigned char *vstr;
1363 unsigned int vlen;
1364 long long vlong;
1365 int pos = (where == QUICKLIST_HEAD) ? 0 : -1;
1366
1367 if (quicklist->count == 0)
1368 return 0;
1369
1370 if (data)
1371 *data = NULL;
1372 if (sz)
1373 *sz = 0;
1374 if (sval)
1375 *sval = -123456789;
1376
1377 quicklistNode *node;
1378 if (where == QUICKLIST_HEAD && quicklist->head) {
1379 node = quicklist->head;
1380 } else if (where == QUICKLIST_TAIL && quicklist->tail) {
1381 node = quicklist->tail;
1382 } else {
1383 return 0;
1384 }
1385
1386 p = ziplistIndex(node->zl, pos);
1387 if (ziplistGet(p, &vstr, &vlen, &vlong)) {
1388 if (vstr) {
1389 if (data)
1390 *data = saver(vstr, vlen);
1391 if (sz)
1392 *sz = vlen;
1393 } else {
1394 if (data)
1395 *data = NULL;
1396 if (sval)
1397 *sval = vlong;
1398 }
1399 quicklistDelIndex(quicklist, node, &p);
1400 return 1;
1401 }
1402 return 0;
1403}
1404
1405/* Return a malloc'd copy of data passed in */
1406REDIS_STATIC void *_quicklistSaver(unsigned char *data, unsigned int sz) {

Callers 2

quicklistPopFunction · 0.85
listTypePopFunction · 0.85

Calls 3

ziplistIndexFunction · 0.85
ziplistGetFunction · 0.85
quicklistDelIndexFunction · 0.85

Tested by

no test coverage detected