[vlc-commits] demux:mkv: remove elements from vector when we delete them
Steve Lhomme
git at videolan.org
Wed Aug 14 18:24:17 CEST 2019
vlc/vlc-3.0 | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Thu Jan 25 11:51:41 2018 +0100| [54784cf59554dd766251c80974d3c27ec92118f3] | committer: Hugo Beauzée-Luyssen
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.
(cherry picked from commit fe2cb5ca7536699672dbc277f2ed0aaff3dd2716)
Signed-off-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>
> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=54784cf59554dd766251c80974d3c27ec92118f3
---
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 f95d9b9c07..804d979b1b 100644
--- a/modules/demux/mkv/demux.cpp
+++ b/modules/demux/mkv/demux.cpp
@@ -701,22 +701,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