[vlc-commits] block_helper: add tail pointer for inserts

Francois Cartegnie git at videolan.org
Wed Oct 26 19:07:02 CEST 2016


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Oct 26 16:45:17 2016 +0200| [163331aac9c7cc275b4db9dea2bb79db7bccfae1] | committer: Francois Cartegnie

block_helper: add tail pointer for inserts

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=163331aac9c7cc275b4db9dea2bb79db7bccfae1
---

 include/vlc_block_helper.h | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/include/vlc_block_helper.h b/include/vlc_block_helper.h
index 331e268..9adc798 100644
--- a/include/vlc_block_helper.h
+++ b/include/vlc_block_helper.h
@@ -29,9 +29,9 @@
 typedef struct block_bytestream_t
 {
     block_t *p_chain;  /**< byte stream head block */
+    block_t **pp_last; /**< tail ppointer for appends */
     block_t *p_block;  /**< byte stream read pointer block */
     size_t   i_offset; /**< byte stream read pointer offset within block */
-    /* TODO? add tail pointer for faster push? */
 } block_bytestream_t;
 
 /*****************************************************************************
@@ -40,6 +40,7 @@ typedef struct block_bytestream_t
 static inline void block_BytestreamInit( block_bytestream_t *p_bytestream )
 {
     p_bytestream->p_chain = p_bytestream->p_block = NULL;
+    p_bytestream->pp_last = &p_bytestream->p_chain;
     p_bytestream->i_offset = 0;
 }
 
@@ -82,12 +83,14 @@ static inline void block_BytestreamFlush( block_bytestream_t *p_bytestream )
     }
 
     p_bytestream->p_chain = p_bytestream->p_block = block;
+    if( p_bytestream->p_chain == NULL )
+        p_bytestream->pp_last = &p_bytestream->p_chain;
 }
 
 static inline void block_BytestreamPush( block_bytestream_t *p_bytestream,
                                          block_t *p_block )
 {
-    block_ChainAppend( &p_bytestream->p_chain, p_block );
+    block_ChainLastAppend( &p_bytestream->pp_last, p_block );
     if( !p_bytestream->p_block ) p_bytestream->p_block = p_block;
 }
 
@@ -109,6 +112,7 @@ static inline block_t *block_BytestreamPop( block_bytestream_t *p_bytestream )
         p_block->i_buffer -= p_bytestream->i_offset;
         p_bytestream->i_offset = 0;
         p_bytestream->p_chain = p_bytestream->p_block = NULL;
+        p_bytestream->pp_last = &p_bytestream->p_chain;
         return p_block;
     }
 
@@ -118,6 +122,7 @@ static inline block_t *block_BytestreamPop( block_bytestream_t *p_bytestream )
     block_t *p_block_old = p_block;
     p_block = p_block->p_next;
     p_block_old->p_next = NULL;
+    p_bytestream->pp_last = &p_block_old->p_next;
 
     return p_block;
 }



More information about the vlc-commits mailing list