[vlc-commits] demux:mkv: remove elements from vector when we delete them

Steve Lhomme git at videolan.org
Thu Jan 25 12:54:24 CET 2018


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Thu Jan 25 11:51:41 2018 +0100| [fe2cb5ca7536699672dbc277f2ed0aaff3dd2716] | committer: Steve Lhomme

demux:mkv: remove elements from vector when we delete them

Rather than setting the value to 0.

This could be useful if we store the actual objects rather than pointers.

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

 modules/demux/mkv/demux.cpp | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/modules/demux/mkv/demux.cpp b/modules/demux/mkv/demux.cpp
index 1789706b52..a17d36dc30 100644
--- a/modules/demux/mkv/demux.cpp
+++ b/modules/demux/mkv/demux.cpp
@@ -704,22 +704,26 @@ bool demux_sys_t::PreloadLinked()
 
 void demux_sys_t::FreeUnused()
 {
-    size_t i;
-    for( i = 0; i < streams.size(); i++ )
+    for (std::vector<matroska_stream_c*>::reverse_iterator i = streams.rbegin();
+         i != streams.rend(); ++i)
     {
-        struct matroska_stream_c *p_s = streams[i];
+        matroska_stream_c *p_s = *i;
         if( !p_s->isUsed() )
         {
-            streams[i] = NULL;
+            std::advance(i, 1);
+            streams.erase( i.base() );
             delete p_s;
         }
     }
-    for( i = 0; i < opened_segments.size(); i++)
+    for (std::vector<matroska_segment_c*>::reverse_iterator i = opened_segments.rbegin();
+         i != opened_segments.rend(); ++i)
     {
-        if( !opened_segments[i]->b_preloaded )
+        matroska_segment_c *p_sg = *i;
+        if( !p_sg->b_preloaded )
         {
-            delete opened_segments[i];
-            opened_segments[i] = NULL;
+            std::advance(i, 1);
+            opened_segments.erase( i.base() );
+            delete p_sg;
         }
     }
 }



More information about the vlc-commits mailing list