mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 11:26:16 +01:00
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 <withnall@endlessm.com>
This commit is contained in:
parent
e0f82b9494
commit
e1e8002998
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user