[vlc-devel] [PATCH 07/14] mkv: Added reconstruct function to EbmlParser

Filip Roséen filip at videolabs.io
Wed Mar 9 12:50:02 CET 2016


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).

Note
-------------------------------------------------------------------------

In the future we should really get rid of the dynamic allocation for the
EbmlParsers completely, but this patch is a step in the right direction
(getting rid of unnecessary new/delete's).
---
 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 );
-- 
2.7.2



More information about the vlc-devel mailing list