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

Function getKeysPrepareResult

src/db.cpp:2124–2147  ·  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

2122 * the result, and can be called repeatedly to enlarge the result array.
2123 */
2124int *getKeysPrepareResult(getKeysResult *result, int numkeys) {
2125 /* GETKEYS_RESULT_INIT initializes keys to NULL, point it to the pre-allocated stack
2126 * buffer here. */
2127 if (!result->keys) {
2128 serverAssert(!result->numkeys);
2129 result->keys = result->keysbuf;
2130 }
2131
2132 /* Resize if necessary */
2133 if (numkeys > result->size) {
2134 if (result->keys != result->keysbuf) {
2135 /* We're not using a static buffer, just (re)alloc */
2136 result->keys = (int*)zrealloc(result->keys, numkeys * sizeof(int));
2137 } else {
2138 /* We are using a static buffer, copy its contents */
2139 result->keys = (int*)zmalloc(numkeys * sizeof(int));
2140 if (result->numkeys)
2141 memcpy(result->keys, result->keysbuf, result->numkeys * sizeof(int));
2142 }
2143 result->size = numkeys;
2144 }
2145
2146 return result->keys;
2147}
2148
2149/* The base case is to use the keys position as given in the command table
2150 * (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 2

zreallocFunction · 0.85
zmallocFunction · 0.85

Tested by

no test coverage detected