Commit a6b280f7 authored by Filip Roséen's avatar Filip Roséen Committed by Jean-Baptiste Kempf

mkv: cleanup of chapter_codec_cmds_c::AddCommand

This function was unnecessary complex, shortened the code by introducing
a helper variable that we can use for direct indexing instead of going
through a switch-statement.

In the future we might want to revert this change, but since we will
always have values in the range [0, 4) I do not see a problem with
shortening the function this way.
Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 0b172d93
......@@ -23,42 +23,32 @@
*****************************************************************************/
#include "chapter_command.hpp"
#include <algorithm>
void chapter_codec_cmds_c::AddCommand( const KaxChapterProcessCommand & command )
{
uint32 codec_time = uint32(-1);
for( size_t i = 0; i < command.ListSize(); i++ )
{
const EbmlElement *k = command[i];
if( MKV_IS_ID( k, KaxChapterProcessTime ) )
if( MKV_CHECKED_PTR_DECL( p_cpt, KaxChapterProcessTime const, command[i] ) )
{
codec_time = static_cast<uint32>( *static_cast<const KaxChapterProcessTime*>( k ) );
codec_time = static_cast<uint32>( *p_cpt );
break;
}
}
for( size_t i = 0; i < command.ListSize(); i++ )
{
const EbmlElement *k = command[i];
if( MKV_IS_ID( k, KaxChapterProcessData ) )
if( MKV_CHECKED_PTR_DECL( p_cpd, KaxChapterProcessData const, command[i] ) )
{
KaxChapterProcessData *p_data = new KaxChapterProcessData( *static_cast<const KaxChapterProcessData*>( k ) );
switch ( codec_time )
{
case 0:
during_cmds.push_back( p_data );
break;
case 1:
enter_cmds.push_back( p_data );
break;
case 2:
leave_cmds.push_back( p_data );
break;
default:
delete p_data;
}
std::vector<KaxChapterProcessData*> *containers[] = {
&during_cmds, /* codec_time = 0 */
&enter_cmds, /* codec_time = 1 */
&leave_cmds /* codec_time = 2 */
};
if( codec_time < 3 )
containers[codec_time]->push_back( new KaxChapterProcessData( *p_cpd ) );
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment