xrandr: Small X11DRV_XRandR_(Get|Set)CurrentMode() code optimisations.

Francois Gouget fgouget at codeweavers.com
Thu Jan 11 08:47:06 CST 2007


---

X11DRV_XRandR_(Get|Set)CurrentMode() both have loops for searching an 
item that continue looping after they have found it. The arrays are 
relatively small and these functions are probably not called very often 
but it still seems much cleaner to me to exit the loop once we have 
found what we were looking for.

Also, as far as I can tell, X11DRV_XRandR_GetCurrentMode() can free the 
XRRScreenConfiguration data and unlock X as soon as it has the size and 
rate it needs. It does not need to keep things locked down while it 
loops.

Finally, it seems to me that X11DRV_XRandR_SetCurrentMode() can return 
success without ever calling XRRSetScreenConfig*() if it is asked for an 
unknown refresh rate and we have a list of refresh rates for the 
specified resolution. I did not fix this one. Can this happen?


 dlls/winex11.drv/xrandr.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/dlls/winex11.drv/xrandr.c b/dlls/winex11.drv/xrandr.c
index 8282794..997fc72 100644
--- a/dlls/winex11.drv/xrandr.c
+++ b/dlls/winex11.drv/xrandr.c
@@ -162,6 +162,8 @@ static int X11DRV_XRandR_GetCurrentMode(void)
     sc = pXRRGetScreenInfo (gdi_display, root);
     size = pXRRConfigCurrentConfiguration (sc, &rot);
     rate = pXRRConfigCurrentRate (sc);
+    pXRRFreeScreenConfigInfo(sc);
+    wine_tsx11_unlock();
     for (i = 0; i < real_xrandr_modes_count; i++)
     {
         if ( (dd_modes[i].dwWidth      == real_xrandr_sizes[size].width ) &&
@@ -169,10 +171,9 @@ static int X11DRV_XRandR_GetCurrentMode(void)
              (dd_modes[i].wRefreshRate == rate                          ) )
           {
               res = i;
+              break;
           }
     }
-    pXRRFreeScreenConfigInfo(sc);
-    wine_tsx11_unlock();
     if (res == -1)
     {
         ERR("In unknown mode, returning default\n");
@@ -226,6 +227,7 @@ static void X11DRV_XRandR_SetCurrentMode(int mode)
                               dd_modes[mode].dwWidth, dd_modes[mode].dwHeight, rate);
                         stat = pXRRSetScreenConfigAndRate (gdi_display, sc, root, 
                                                           size, rot, rate, CurrentTime);
+                        break;
                     }
                 }
             }
@@ -235,6 +237,7 @@ static void X11DRV_XRandR_SetCurrentMode(int mode)
 		      dd_modes[mode].dwWidth, dd_modes[mode].dwHeight);
                 stat = pXRRSetScreenConfig (gdi_display, sc, root, size, rot, CurrentTime);
             }
+            break;
         }
     }
     pXRRFreeScreenConfigInfo(sc);
-- 
1.4.4.2



More information about the wine-patches mailing list