From b23f2ab3dd9d8d3174a5df071bbb3023310f220d Mon Sep 17 00:00:00 2001 From: Kristen McWilliam Date: Sat, 18 Sep 2021 13:12:25 -0400 Subject: [PATCH] Refactor if-else chain in Placement::place to a switch statement Was using a long & fragmented if-else chain. A switch statement is often more performant, as well as being easier to read and modify. --- src/placement.cpp | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/placement.cpp b/src/placement.cpp index 5385b66648..169f97a213 100644 --- a/src/placement.cpp +++ b/src/placement.cpp @@ -70,28 +70,39 @@ void Placement::place(AbstractClient *c, const QRect &area) void Placement::place(AbstractClient *c, const QRect &area, Policy policy, Policy nextPlacement) { - if (policy == Unknown) + switch (policy) { + case Unknown: policy = Default; - if (policy == Default) + break; + case Default: policy = options->placement(); - if (policy == NoPlacement) + break; + case NoPlacement: return; - else if (policy == Random) + case Random: placeAtRandom(c, area, nextPlacement); - else if (policy == Cascade) + break; + case Cascade: placeCascaded(c, area, nextPlacement); - else if (policy == Centered) + break; + case Centered: placeCentered(c, area, nextPlacement); - else if (policy == ZeroCornered) + break; + case ZeroCornered: placeZeroCornered(c, area, nextPlacement); - else if (policy == UnderMouse) + break; + case UnderMouse: placeUnderMouse(c, area, nextPlacement); - else if (policy == OnMainWindow) + break; + case OnMainWindow: placeOnMainWindow(c, area, nextPlacement); - else if (policy == Maximizing) + break; + case Maximizing: placeMaximizing(c, area, nextPlacement); - else + break; + default: placeSmart(c, area, nextPlacement); + } if (options->borderSnapZone()) { // snap to titlebar / snap to window borders on inner screen edges