vlc | branch: master | Rémi Denis-Courmont <r...@remlab.net> | Tue Feb 21 22:00:28 2017 +0200| [7e1aa4fb31be60cde48e28bd2b6088fbf4cc9b44] | committer: Rémi Denis-Courmont
vlc_arrays: alias (INSERT|REMOVE)_ELEM to TAB_(INSERT|ERASE) At this point, the two sets of helpers did essentially the same thing. The only difference was that REMOVE_ELEM systematically shrinks the table allocation, while TAB_ERASE waits for the table to become empty. > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7e1aa4fb31be60cde48e28bd2b6088fbf4cc9b44 --- include/vlc_arrays.h | 45 ++++++--------------------------------------- 1 file changed, 6 insertions(+), 39 deletions(-) diff --git a/include/vlc_arrays.h b/include/vlc_arrays.h index c94e1de..dcdfa7a 100644 --- a/include/vlc_arrays.h +++ b/include/vlc_arrays.h @@ -37,45 +37,6 @@ static inline void *realloc_down( void *ptr, size_t size ) return ret ? ret : ptr; } -/** - * Simple dynamic array handling. Array is realloced at each insert/removal - */ -#define INSERT_ELEM( p_ar, i_oldsize, i_pos, elem ) \ - do \ - { \ - if( !(i_oldsize) ) (p_ar) = NULL; \ - (p_ar) = realloc( p_ar, ((i_oldsize) + 1) * sizeof(*(p_ar)) ); \ - if( !(p_ar) ) abort(); \ - if( (i_oldsize) - (i_pos) ) \ - { \ - memmove( (p_ar) + (i_pos) + 1, (p_ar) + (i_pos), \ - ((i_oldsize) - (i_pos)) * sizeof( *(p_ar) ) ); \ - } \ - (p_ar)[(i_pos)] = elem; \ - (i_oldsize)++; \ - } \ - while( 0 ) - -#define REMOVE_ELEM( p_ar, i_size, i_pos ) \ - do \ - { \ - if( (i_size) - (i_pos) - 1 ) \ - { \ - memmove( (p_ar) + (i_pos), \ - (p_ar) + (i_pos) + 1, \ - ((i_size) - (i_pos) - 1) * sizeof( *(p_ar) ) ); \ - } \ - if( i_size > 1 ) \ - (p_ar) = realloc_down( p_ar, ((i_size) - 1) * sizeof( *(p_ar) ) );\ - else \ - { \ - free( p_ar ); \ - (p_ar) = NULL; \ - } \ - (i_size)--; \ - } \ - while( 0 ) - #define TAB_INIT( count, tab ) \ do { \ (count) = 0; \ @@ -152,6 +113,12 @@ static inline void *realloc_down( void *ptr, size_t size ) #define TAB_INSERT( count, tab, p, index ) \ TAB_INSERT_CAST( , count, tab, p, index ) +#define INSERT_ELEM( p_ar, i_oldsize, i_pos, elem ) \ + TAB_INSERT( i_oldsize, p_ar, elem, i_pos ) + +#define REMOVE_ELEM( p_ar, i_size, i_pos ) \ + TAB_ERASE( i_size, p_ar, i_pos ) + /** * Binary search in a sorted array. The key must be comparable by < and > * \param entries array of entries _______________________________________________ vlc-commits mailing list vlc-commits@videolan.org https://mailman.videolan.org/listinfo/vlc-commits