[vlc-devel] [PATCH 1/4] demux: mkv: HandleKeyEvent: negate if to prevent nesting
Filip Roséen
filip at atch.se
Sun Jul 22 08:16:32 CEST 2018
The relevant if statement is the same for all switch cases, meaning
that we can rewrite it to abort early, and remove the duplicate check
from each case.
---
modules/demux/mkv/events.cpp | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/modules/demux/mkv/events.cpp b/modules/demux/mkv/events.cpp
index 4c94385e9e..6357971a02 100644
--- a/modules/demux/mkv/events.cpp
+++ b/modules/demux/mkv/events.cpp
@@ -178,10 +178,12 @@ void event_thread_t::HandleKeyEvent( EventInfo const& ev )
uint16 i_curr_button = p_sys->dvd_interpretor.GetSPRM( 0x88 );
+ if( i_curr_button <= 0 || i_curr_button > pci->hli.hl_gi.btn_ns )
+ return;
+
switch( ev.action.id )
{
case ACTIONID_NAV_LEFT:
- if ( i_curr_button > 0 && i_curr_button <= pci->hli.hl_gi.btn_ns )
{
btni_t *p_button_ptr = &(pci->hli.btnit[i_curr_button-1]);
if ( p_button_ptr->left > 0 && p_button_ptr->left <= pci->hli.hl_gi.btn_ns )
@@ -204,7 +206,6 @@ void event_thread_t::HandleKeyEvent( EventInfo const& ev )
}
break;
case ACTIONID_NAV_RIGHT:
- if ( i_curr_button > 0 && i_curr_button <= pci->hli.hl_gi.btn_ns )
{
btni_t *p_button_ptr = &(pci->hli.btnit[i_curr_button-1]);
if ( p_button_ptr->right > 0 && p_button_ptr->right <= pci->hli.hl_gi.btn_ns )
@@ -227,7 +228,6 @@ void event_thread_t::HandleKeyEvent( EventInfo const& ev )
}
break;
case ACTIONID_NAV_UP:
- if ( i_curr_button > 0 && i_curr_button <= pci->hli.hl_gi.btn_ns )
{
btni_t *p_button_ptr = &(pci->hli.btnit[i_curr_button-1]);
if ( p_button_ptr->up > 0 && p_button_ptr->up <= pci->hli.hl_gi.btn_ns )
@@ -250,7 +250,6 @@ void event_thread_t::HandleKeyEvent( EventInfo const& ev )
}
break;
case ACTIONID_NAV_DOWN:
- if ( i_curr_button > 0 && i_curr_button <= pci->hli.hl_gi.btn_ns )
{
btni_t *p_button_ptr = &(pci->hli.btnit[i_curr_button-1]);
if ( p_button_ptr->down > 0 && p_button_ptr->down <= pci->hli.hl_gi.btn_ns )
@@ -273,7 +272,6 @@ void event_thread_t::HandleKeyEvent( EventInfo const& ev )
}
break;
case ACTIONID_NAV_ACTIVATE:
- if ( i_curr_button > 0 && i_curr_button <= pci->hli.hl_gi.btn_ns )
{
btni_t button_ptr = pci->hli.btnit[i_curr_button-1];
--
2.18.0
More information about the vlc-devel
mailing list