[vlc-commits] demux: mkv: HandleKeyEvent: negate if to prevent nesting

Filip Roséen git at videolan.org
Sun Jul 22 23:36:08 CEST 2018


vlc | branch: master | Filip Roséen <filip at atch.se> | Sun Jul 22 08:16:32 2018 +0200| [768e668c180be34289410999493311d3d92ca17d] | committer: Jean-Baptiste Kempf

demux: mkv: HandleKeyEvent: negate if to prevent nesting

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.

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

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

 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 684db42599..04cd9f619d 100644
--- a/modules/demux/mkv/events.cpp
+++ b/modules/demux/mkv/events.cpp
@@ -175,10 +175,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 )
@@ -201,7 +203,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 )
@@ -224,7 +225,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 )
@@ -247,7 +247,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 )
@@ -270,7 +269,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];
 



More information about the vlc-commits mailing list