mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-10-30 16:02:18 +01:00 
			
		
		
		
	array: add internal ptr_array_new() helper for creating GPtrArray
Unify the creation of GPtrArray. Maybe we will add yet another constructor for creating %NULL terminated arrays. Unify the constructors by adding an internal helper method. The alternative instead of adding a ptr_array_new() helper, would be to let everybody call g_ptr_array_full(). For no strong reasons, choose this approach because the compiler is more eager to inline the static helper as it would inlining g_ptr_array_full().
This commit is contained in:
		| @@ -1071,6 +1071,27 @@ struct _GRealPtrArray | |||||||
| static void g_ptr_array_maybe_expand (GRealPtrArray *array, | static void g_ptr_array_maybe_expand (GRealPtrArray *array, | ||||||
|                                       guint          len); |                                       guint          len); | ||||||
|  |  | ||||||
|  | static GPtrArray * | ||||||
|  | ptr_array_new (guint reserved_size, | ||||||
|  |                GDestroyNotify element_free_func) | ||||||
|  | { | ||||||
|  |   GRealPtrArray *array; | ||||||
|  |  | ||||||
|  |   array = g_slice_new (GRealPtrArray); | ||||||
|  |  | ||||||
|  |   array->pdata = NULL; | ||||||
|  |   array->len = 0; | ||||||
|  |   array->alloc = 0; | ||||||
|  |   array->element_free_func = element_free_func; | ||||||
|  |  | ||||||
|  |   g_atomic_ref_count_init (&array->ref_count); | ||||||
|  |  | ||||||
|  |   if (reserved_size != 0) | ||||||
|  |     g_ptr_array_maybe_expand (array, reserved_size); | ||||||
|  |  | ||||||
|  |   return (GPtrArray *) array; | ||||||
|  | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * g_ptr_array_new: |  * g_ptr_array_new: | ||||||
|  * |  * | ||||||
| @@ -1081,7 +1102,7 @@ static void g_ptr_array_maybe_expand (GRealPtrArray *array, | |||||||
| GPtrArray* | GPtrArray* | ||||||
| g_ptr_array_new (void) | g_ptr_array_new (void) | ||||||
| { | { | ||||||
|   return g_ptr_array_sized_new (0); |   return ptr_array_new (0, NULL); | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -1190,8 +1211,8 @@ g_ptr_array_copy (GPtrArray *array, | |||||||
|  |  | ||||||
|   g_return_val_if_fail (array != NULL, NULL); |   g_return_val_if_fail (array != NULL, NULL); | ||||||
|  |  | ||||||
|   new_array = g_ptr_array_sized_new (array->len); |   new_array = ptr_array_new (array->len, | ||||||
|   g_ptr_array_set_free_func (new_array, ((GRealPtrArray *) array)->element_free_func); |                              ((GRealPtrArray *) array)->element_free_func); | ||||||
|  |  | ||||||
|   if (func != NULL) |   if (func != NULL) | ||||||
|     { |     { | ||||||
| @@ -1225,21 +1246,7 @@ g_ptr_array_copy (GPtrArray *array, | |||||||
| GPtrArray* | GPtrArray* | ||||||
| g_ptr_array_sized_new (guint reserved_size) | g_ptr_array_sized_new (guint reserved_size) | ||||||
| { | { | ||||||
|   GRealPtrArray *array; |   return ptr_array_new (reserved_size, NULL); | ||||||
|  |  | ||||||
|   array = g_slice_new (GRealPtrArray); |  | ||||||
|  |  | ||||||
|   array->pdata = NULL; |  | ||||||
|   array->len = 0; |  | ||||||
|   array->alloc = 0; |  | ||||||
|   array->element_free_func = NULL; |  | ||||||
|  |  | ||||||
|   g_atomic_ref_count_init (&array->ref_count); |  | ||||||
|  |  | ||||||
|   if (reserved_size != 0) |  | ||||||
|     g_ptr_array_maybe_expand (array, reserved_size); |  | ||||||
|  |  | ||||||
|   return (GPtrArray*) array;   |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -1290,12 +1297,7 @@ g_array_copy (GArray *array) | |||||||
| GPtrArray* | GPtrArray* | ||||||
| g_ptr_array_new_with_free_func (GDestroyNotify element_free_func) | g_ptr_array_new_with_free_func (GDestroyNotify element_free_func) | ||||||
| { | { | ||||||
|   GPtrArray *array; |   return ptr_array_new (0, element_free_func); | ||||||
|  |  | ||||||
|   array = g_ptr_array_new (); |  | ||||||
|   g_ptr_array_set_free_func (array, element_free_func); |  | ||||||
|  |  | ||||||
|   return array; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -1320,12 +1322,7 @@ GPtrArray* | |||||||
| g_ptr_array_new_full (guint          reserved_size, | g_ptr_array_new_full (guint          reserved_size, | ||||||
|                       GDestroyNotify element_free_func) |                       GDestroyNotify element_free_func) | ||||||
| { | { | ||||||
|   GPtrArray *array; |   return ptr_array_new (reserved_size, element_free_func); | ||||||
|  |  | ||||||
|   array = g_ptr_array_sized_new (reserved_size); |  | ||||||
|   g_ptr_array_set_free_func (array, element_free_func); |  | ||||||
|  |  | ||||||
|   return array; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user