[vlc-commits] mkv: Added reconstruct function to EbmlParser

Filip Roséen git at videolan.org
Wed Mar 9 12:59:42 CET 2016


vlc | branch: master | Filip Roséen <filip at videolabs.io> | Wed Mar  9 12:50:02 2016 +0100| [6487b499943b3a014abf4239dac0a0119793fcb3] | committer: Jean-Baptiste Kempf

mkv: Added reconstruct function to EbmlParser

The two overloads of EbmlParser::reconstruct has been added due to the
fact that there are _a lot_ of places in the code following the below:

    delete ep;
    ep = new EbmlParser (a, b, c, b);

The above will, unless the compiler feels cocky and optimizes it to what
is included in this patch. First free the memory used, and then allocate
new memory for a new EbmlParser.

Instead of doing what is effectively a reallocation, this patch
introduces EbmlParser::reconstruct which will reconstruct the object
in-place (without actually having to reallocate the underlying storage).

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/demux/mkv/Ebml_parser.cpp |   15 +++++++++++++++
 modules/demux/mkv/Ebml_parser.hpp |    3 +++
 2 files changed, 18 insertions(+)

diff --git a/modules/demux/mkv/Ebml_parser.cpp b/modules/demux/mkv/Ebml_parser.cpp
index 2168158..7bcce84 100644
--- a/modules/demux/mkv/Ebml_parser.cpp
+++ b/modules/demux/mkv/Ebml_parser.cpp
@@ -63,6 +63,21 @@ EbmlParser::~EbmlParser( void )
     }
 }
 
+void EbmlParser::reconstruct( EbmlStream* es, EbmlElement* el_start, demux_t* p_demux )
+{
+    this->reconstruct( es, el_start, p_demux, var_InheritBool( p_demux, "mkv-use-dummy" ) );
+}
+
+void EbmlParser::reconstruct( EbmlStream* es, EbmlElement* el_start, demux_t* p_demux,
+  bool b_with_dummy)
+{
+    this->~EbmlParser();
+
+    new( static_cast<void*>( this ) ) EbmlParser(
+      es, el_start, p_demux, b_with_dummy
+    );
+}
+
 EbmlElement* EbmlParser::UnGet( uint64 i_block_pos, uint64 i_cluster_pos )
 {
     if ( mi_user_level > mi_level )
diff --git a/modules/demux/mkv/Ebml_parser.hpp b/modules/demux/mkv/Ebml_parser.hpp
index 109c572..5dc425f 100644
--- a/modules/demux/mkv/Ebml_parser.hpp
+++ b/modules/demux/mkv/Ebml_parser.hpp
@@ -37,6 +37,9 @@ class EbmlParser
                 bool b_with_dummy );
     ~EbmlParser( void );
 
+    void reconstruct( EbmlStream*, EbmlElement*, demux_t*);
+    void reconstruct( EbmlStream*, EbmlElement*, demux_t*, bool b_with_dummy );
+
     void Up( void );
     void Down( void );
     void Reset( demux_t *p_demux );



More information about the vlc-commits mailing list