mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-20 15:48:54 +02:00
gstrvbuilder: Add g_strv_builder_take
g_strv_builder_take() allows to transfer ownership of the passed in string. This can be useful to avoid additional allocations when using functions that transfer ownership to the caller like g_strdup_printf(). The testcase uses g_strv_builder_take and g_strv_builder_add to demo that calls can be mixed.
This commit is contained in:
@@ -156,6 +156,24 @@ g_strv_builder_add_many (GStrvBuilder *builder,
|
||||
va_end (var_args);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_strv_builder_take:
|
||||
* @builder: a #GStrvBuilder
|
||||
* @value: (transfer full): a string.
|
||||
* Ownership of the string is transferred to the #GStrvBuilder
|
||||
*
|
||||
* Add a string to the end of the array. After @value belongs to the
|
||||
* #GStrvBuilder and may no longer be modified by the caller.
|
||||
*
|
||||
* Since 2.80
|
||||
*/
|
||||
void
|
||||
g_strv_builder_take (GStrvBuilder *builder,
|
||||
char *value)
|
||||
{
|
||||
g_ptr_array_add (&builder->array, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_strv_builder_end:
|
||||
* @builder: a #GStrvBuilder
|
||||
|
Reference in New Issue
Block a user