mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 23:16:14 +01:00
g_strsplit: Use a pre-allocated GArray when max_tokens is provided
In case max_tokens is provided, we can safely pre-allocate the GArray to the max_tokens value plus one for the NULL terminating value.
This commit is contained in:
parent
88d4b3b365
commit
0618f5eb82
@ -2425,9 +2425,15 @@ g_strsplit (const gchar *string,
|
||||
g_return_val_if_fail (delimiter[0] != '\0', NULL);
|
||||
|
||||
if (max_tokens < 1)
|
||||
max_tokens = G_MAXINT;
|
||||
{
|
||||
max_tokens = G_MAXINT;
|
||||
string_list = g_ptr_array_new ();
|
||||
}
|
||||
else
|
||||
{
|
||||
string_list = g_ptr_array_new_full (max_tokens + 1, NULL);
|
||||
}
|
||||
|
||||
string_list = g_ptr_array_new ();
|
||||
remainder = string;
|
||||
s = strstr (remainder, delimiter);
|
||||
if (s)
|
||||
|
Loading…
Reference in New Issue
Block a user