From c3ba9aeba3a3b92b9d804d2f2b3d0518d0d2fd9a Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Fri, 8 May 2015 13:19:11 +0200 Subject: [PATCH] wmaker: moved calculation of internal offset in handleDockMove outside the loop As pointed by the "checkpatch.pl" script, one line was too long in respect of the coding style. This line contains the calculation of an offset when storing a value in an array, as this offset is a constant during all the loop, this patch is calculating the offset only once before the loop and then uses this result, which should make the code faster (although gcc may already optimise this kind of things), makes it compliant with coding style, and takes the opportunity to explain the reasons behind this offset. Signed-off-by: Christophe CURIS --- src/dock.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/dock.c b/src/dock.c index 2f325e99..99c137ad 100644 --- a/src/dock.c +++ b/src/dock.c @@ -3835,12 +3835,24 @@ static void handleDockMove(WDock *dock, WAppIcon *aicon, XEvent *event) XUngrabPointer(dpy, CurrentTime); if (dock->type == WM_DRAWER) { Window wins[dock->icon_count]; + int offset_index; + + /* + * When the dock is on the Right side, the index of the icons are negative to + * reflect the fact that they are placed on the other side of the dock; we use + * an offset here so we can have an always positive index for the storage in + * the 'wins' array. + */ + if (dock->on_right_side) + offset_index = dock->icon_count - 1; + else + offset_index = 0; for (i = 0; i < dock->max_icons; i++) { tmpaicon = dock->icon_array[i]; if (tmpaicon == NULL) continue; - wins[ tmpaicon->xindex + (dock->on_right_side ? dock->icon_count - 1 : 0) ] = tmpaicon->icon->core->window; + wins[tmpaicon->xindex + offset_index] = tmpaicon->icon->core->window; } slide_windows(wins, dock->icon_count, (dock->on_right_side ? x - (dock->icon_count - 1) * ICON_SIZE : x),