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

Function getKeysPrepareResult

app/redis-6.2.6/src/db.c:1575–1598  ·  view source on GitHub ↗

Prepare the getKeysResult struct to hold numkeys, either by using the * pre-allocated keysbuf or by allocating a new array on the heap. * * This function must be called at least once before starting to populate * the result, and can be called repeatedly to enlarge the result array. */

Source from the content-addressed store, hash-verified

1573 * the result, and can be called repeatedly to enlarge the result array.
1574 */
1575int *getKeysPrepareResult(getKeysResult *result, int numkeys) {
1576 /* GETKEYS_RESULT_INIT initializes keys to NULL, point it to the pre-allocated stack
1577 * buffer here. */
1578 if (!result->keys) {
1579 serverAssert(!result->numkeys);
1580 result->keys = result->keysbuf;
1581 }
1582
1583 /* Resize if necessary */
1584 if (numkeys > result->size) {
1585 if (result->keys != result->keysbuf) {
1586 /* We're not using a static buffer, just (re)alloc */
1587 result->keys = zrealloc(result->keys, numkeys * sizeof(int));
1588 } else {
1589 /* We are using a static buffer, copy its contents */
1590 result->keys = zmalloc(numkeys * sizeof(int));
1591 if (result->numkeys)
1592 memcpy(result->keys, result->keysbuf, result->numkeys * sizeof(int));
1593 }
1594 result->size = numkeys;
1595 }
1596
1597 return result->keys;
1598}
1599
1600/* The base case is to use the keys position as given in the command table
1601 * (firstkey, lastkey, step). */

Callers 10

getKeysUsingCommandTableFunction · 0.85
genericGetKeysFunction · 0.85
sortGetKeysFunction · 0.85
migrateGetKeysFunction · 0.85
georadiusGetKeysFunction · 0.85
lcsGetKeysFunction · 0.85
memoryGetKeysFunction · 0.85
xreadGetKeysFunction · 0.85
RM_KeyAtPosFunction · 0.85

Calls 3

zreallocFunction · 0.85
zmallocFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected