Commit e1e80029 authored by Philip Withnall's avatar Philip Withnall

garray: Optimise over-allocations with g_array_insert_vals()

When over-allocating by inserting values off the end of an array, maybe
expand the array once, rather than twice (once for setting the size and
once for appending the values).

Suggestion by Peter Bloomfield (@peterb) as a follow-up to #1374.
Signed-off-by: Philip Withnall's avatarPhilip Withnall <>
parent e0f82b94
......@@ -546,7 +546,10 @@ g_array_insert_vals (GArray *farray,
/* Is the index off the end of the array, and hence do we need to over-allocate
* and clear some elements? */
if (index_ >= array->len)
g_array_maybe_expand (array, index_ - array->len + len);
return g_array_append_vals (g_array_set_size (farray, index_), data, len);
g_array_maybe_expand (array, len);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment