Pull up to `chunk` start nodes (INT_MAX: all of them) into *out. */
| 6145 | |
| 6146 | /* Pull up to `chunk` start nodes (INT_MAX: all of them) into *out. */ |
| 6147 | static int pull_start_nodes(start_source_t *src, int chunk, cbm_node_t **out, int *count) { |
| 6148 | int cap = chunk < CYPHER_STREAM_CHUNK ? chunk : CYPHER_STREAM_CHUNK; |
| 6149 | cbm_node_t *nodes = cbm_alloc(CBM_MEM_CLASS_OTHER, (size_t)cap * sizeof(cbm_node_t)); |
| 6150 | int n = 0; |
| 6151 | while (nodes) { |
| 6152 | n += start_source_next(src, nodes + n, cap - n); |
| 6153 | if (n < cap || cap == chunk) { |
| 6154 | break; /* scan exhausted, or the chunk is full */ |
| 6155 | } |
| 6156 | int grown_cap = cap > chunk / PAIR_LEN ? chunk : cap * PAIR_LEN; |
| 6157 | cbm_node_t *grown = |
| 6158 | cbm_realloc(CBM_MEM_CLASS_OTHER, nodes, (size_t)grown_cap * sizeof(cbm_node_t)); |
| 6159 | if (!grown) { |
| 6160 | start_nodes_free(nodes, n); |
| 6161 | nodes = NULL; |
| 6162 | break; |
| 6163 | } |
| 6164 | nodes = grown; |
| 6165 | cap = grown_cap; |
| 6166 | } |
| 6167 | *out = nodes; |
| 6168 | *count = nodes ? n : 0; |
| 6169 | return nodes ? 0 : CBM_NOT_FOUND; |
| 6170 | } |
| 6171 | |
| 6172 | /* Run the next chunk of start nodes through the pipeline into the sink. The |
| 6173 | * start nodes' strings move into their bindings and are released with them. |
no test coverage detected