[vlc-commits] macosx: optimize scrollwheel code by saving 3 objc selector calls per run

Felix Paul Kühne git at videolan.org
Mon May 28 19:58:54 CEST 2012


vlc/vlc-2.0 | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Mon May 28 15:51:30 2012 +0200| [40ad28f76c9ed4243381bf4a30cecb0908d252f1] | committer: Felix Paul Kühne

macosx: optimize scrollwheel code by saving 3 objc selector calls per run

no functional change
(cherry picked from commit d9fb60bec03044bb7bc20e9a18d52f43f940b75b)

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=40ad28f76c9ed4243381bf4a30cecb0908d252f1
---

 modules/gui/macosx/controls.m |   23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/modules/gui/macosx/controls.m b/modules/gui/macosx/controls.m
index 4deced9..1570401 100644
--- a/modules/gui/macosx/controls.m
+++ b/modules/gui/macosx/controls.m
@@ -258,49 +258,54 @@
 {
     intf_thread_t * p_intf = VLCIntf;
     BOOL b_invertedEventFromDevice = NO;
+    CGFloat f_deltaY, f_deltaX = .0;
+
     if (OSX_LION)
     {
         if ([theEvent isDirectionInvertedFromDevice])
             b_invertedEventFromDevice = YES;
     }
 
-    float f_yabsvalue = [theEvent deltaY] > 0.0f ? [theEvent deltaY] : -[theEvent deltaY];
-    float f_xabsvalue = [theEvent deltaX] > 0.0f ? [theEvent deltaX] : -[theEvent deltaX];
-    int i, i_yvlckey, i_xvlckey;
+    f_deltaY = [theEvent deltaY];
+    f_deltaX = [theEvent deltaX];
+
+    CGFloat f_yabsvalue = f_deltaY > 0.0f ? f_deltaY : -f_deltaY;
+    CGFloat f_xabsvalue = f_deltaX > 0.0f ? f_deltaX : -f_deltaX;
+    int i_yvlckey, i_xvlckey;
 
     if (b_invertedEventFromDevice)
     {
-        if ([theEvent deltaY] > 0.0f)
+        if (f_deltaY > 0.0f)
             i_yvlckey = KEY_MOUSEWHEELDOWN;
         else
             i_yvlckey = KEY_MOUSEWHEELUP;
 
-        if ([theEvent deltaX] > 0.0f)
+        if (f_deltaX > 0.0f)
             i_xvlckey = KEY_MOUSEWHEELRIGHT;
         else
             i_xvlckey = KEY_MOUSEWHEELLEFT;
     }
     else
     {
-        if ([theEvent deltaY] < 0.0f)
+        if (f_deltaY < 0.0f)
             i_yvlckey = KEY_MOUSEWHEELDOWN;
         else
             i_yvlckey = KEY_MOUSEWHEELUP;
 
-        if ([theEvent deltaX] < 0.0f)
+        if (f_deltaX < 0.0f)
             i_xvlckey = KEY_MOUSEWHEELRIGHT;
         else
             i_xvlckey = KEY_MOUSEWHEELLEFT;
     }
 
     /* Send multiple key event, depending on the intensity of the event */
-    for (i = 0; i < (int)(f_yabsvalue/4.+1.) && f_yabsvalue > 0.05 ; i++)
+    for (NSUInteger i = 0; i < (int)(f_yabsvalue/4.+1.) && f_yabsvalue > 0.05 ; i++)
         var_SetInteger( p_intf->p_libvlc, "key-pressed", i_yvlckey );
 
     /* Prioritize Y event (sound volume) over X event */
     if (f_yabsvalue < 0.05)
     {
-        for (i = 0; i < (int)(f_xabsvalue/6.+1.) && f_xabsvalue > 0.05; i++)
+        for (NSUInteger i = 0; i < (int)(f_xabsvalue/6.+1.) && f_xabsvalue > 0.05; i++)
          var_SetInteger( p_intf->p_libvlc, "key-pressed", i_xvlckey );
     }
 }



More information about the vlc-commits mailing list