Improve allocation logic
This commit is contained in:
parent
242af84c99
commit
23dbcf2c58
@ -72,33 +72,24 @@ static bool get_all_emanating_edges(HE_vert const * const vert,
|
|||||||
HE_edge ***edge_array_out,
|
HE_edge ***edge_array_out,
|
||||||
uint32_t *ec_out)
|
uint32_t *ec_out)
|
||||||
{
|
{
|
||||||
uint32_t ec = 0, /* edge count */
|
uint32_t ec = 0; /* edge count */
|
||||||
rc = 0; /* realloc count */
|
HE_edge **edge_array = NULL;
|
||||||
uint32_t const approx_ec = 20; /* allocation chunk */
|
|
||||||
HE_edge **edge_array;
|
|
||||||
|
|
||||||
if (!edge_array_out || !vert || !ec_out)
|
if (!edge_array_out || !vert || !ec_out)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
edge_array = malloc(sizeof(HE_edge*) * approx_ec);
|
|
||||||
CHECK_PTR_VAL(edge_array);
|
|
||||||
|
|
||||||
HE_edge *edge = vert->edge;
|
HE_edge *edge = vert->edge;
|
||||||
|
|
||||||
/* build an array of emanating edges */
|
/* build an array of emanating edges */
|
||||||
do {
|
do {
|
||||||
|
REALLOC(edge_array,
|
||||||
|
sizeof(HE_edge*) * (ec + 1));
|
||||||
|
|
||||||
edge_array[ec] = edge;
|
edge_array[ec] = edge;
|
||||||
|
|
||||||
edge = edge->pair->next;
|
edge = edge->pair->next;
|
||||||
ec++;
|
ec++;
|
||||||
|
|
||||||
/* allocate more chunks */
|
|
||||||
if (ec >= approx_ec) {
|
|
||||||
REALLOC(edge_array, sizeof(HE_edge*)
|
|
||||||
* approx_ec * (rc + 2));
|
|
||||||
rc++;
|
|
||||||
}
|
|
||||||
|
|
||||||
} while (edge && edge != vert->edge);
|
} while (edge && edge != vert->edge);
|
||||||
|
|
||||||
/* set out-pointers */
|
/* set out-pointers */
|
||||||
|
Loading…
Reference in New Issue
Block a user