mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	dynarray: Add pa_dynarray_remove_by_index()
Also, remove the talk about "fast" variants of functions that remove entries from an array. Currently there's no need for order-preserving functions, so all functions are "fast".
This commit is contained in:
		
							parent
							
								
									e5cf7e4a07
								
							
						
					
					
						commit
						9efe77c8e5
					
				
					 2 changed files with 24 additions and 6 deletions
				
			
		| 
						 | 
					@ -86,6 +86,24 @@ void *pa_dynarray_last(pa_dynarray *array) {
 | 
				
			||||||
    return array->data[array->n_entries - 1];
 | 
					    return array->data[array->n_entries - 1];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int pa_dynarray_remove_by_index(pa_dynarray *array, unsigned i) {
 | 
				
			||||||
 | 
					    void *entry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pa_assert(array);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (i >= array->n_entries)
 | 
				
			||||||
 | 
					        return -PA_ERR_NOENTITY;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    entry = array->data[i];
 | 
				
			||||||
 | 
					    array->data[i] = array->data[array->n_entries - 1];
 | 
				
			||||||
 | 
					    array->n_entries--;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (array->free_cb)
 | 
				
			||||||
 | 
					        array->free_cb(entry);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *pa_dynarray_steal_last(pa_dynarray *array) {
 | 
					void *pa_dynarray_steal_last(pa_dynarray *array) {
 | 
				
			||||||
    pa_assert(array);
 | 
					    pa_assert(array);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,12 +33,9 @@ typedef struct pa_dynarray pa_dynarray;
 | 
				
			||||||
 * from the array without freeing them, while also having the free callback
 | 
					 * from the array without freeing them, while also having the free callback
 | 
				
			||||||
 * set, the functions with "steal" in their name can be used.
 | 
					 * set, the functions with "steal" in their name can be used.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Removing items from the middle of the array causes the subsequent items to
 | 
					 * Removing items from the middle of the array causes the last item to be
 | 
				
			||||||
 * be moved to fill the gap, so it's not efficient with large arrays. If the
 | 
					 * moved to the place of the removed item. That is, array ordering is not
 | 
				
			||||||
 * order of the array is not important, however, functions with "fast" in their
 | 
					 * preserved.
 | 
				
			||||||
 * name can be used, in which case the gap is filled by moving only the last
 | 
					 | 
				
			||||||
 * item(s). XXX: Currently there are no functions with "fast" in their name,
 | 
					 | 
				
			||||||
 * but such functions will be added if they are ever needed.
 | 
					 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * The array doesn't support storing NULL pointers. */
 | 
					 * The array doesn't support storing NULL pointers. */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -51,6 +48,9 @@ void *pa_dynarray_get(pa_dynarray *array, unsigned i);
 | 
				
			||||||
/* Returns the last element, or NULL if the array is empty. */
 | 
					/* Returns the last element, or NULL if the array is empty. */
 | 
				
			||||||
void *pa_dynarray_last(pa_dynarray *array);
 | 
					void *pa_dynarray_last(pa_dynarray *array);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Returns -PA_ERR_NOENTITY if i is out of bounds, and zero otherwise. */
 | 
				
			||||||
 | 
					int pa_dynarray_remove_by_index(pa_dynarray *array, unsigned i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Returns the removed item, or NULL if the array is empty. */
 | 
					/* Returns the removed item, or NULL if the array is empty. */
 | 
				
			||||||
void *pa_dynarray_steal_last(pa_dynarray *array);
 | 
					void *pa_dynarray_steal_last(pa_dynarray *array);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue