From e0bbf5c87f621be233877217dd3e26770342c927 Mon Sep 17 00:00:00 2001 From: Vlad Zagorodniy Date: Sun, 1 Jul 2018 10:45:39 +0300 Subject: [PATCH] Use std::transform in libkwineffects implementation part Summary: Don't use raw loops, instead, use appropriate algorithm from STL to map a list of toplevels to a list of EffectWindow. Test Plan: Tested Cover switch, Flip switch, Dialog parent, and Dim inactive effect. They all still work. Reviewers: #kwin, graesslin Reviewed By: #kwin, graesslin Subscribers: graesslin, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D13821 --- effects.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/effects.cpp b/effects.cpp index 266479548e..a3864a12ba 100644 --- a/effects.cpp +++ b/effects.cpp @@ -1078,10 +1078,12 @@ void EffectsHandlerImpl::setTabBoxDesktop(int desktop) EffectWindowList EffectsHandlerImpl::currentTabBoxWindowList() const { #ifdef KWIN_BUILD_TABBOX - EffectWindowList ret; const auto clients = TabBox::TabBox::self()->currentClientList(); - for (auto c : clients) - ret.append(c->effectWindow()); + EffectWindowList ret; + ret.reserve(clients.size()); + std::transform(std::cbegin(clients), std::cend(clients), + std::back_inserter(ret), + [](auto client) { return client->effectWindow(); }); return ret; #else return EffectWindowList(); @@ -1700,10 +1702,12 @@ template EffectWindowList getMainWindows(Toplevel *toplevel) { T *c = static_cast(toplevel); - EffectWindowList ret; const auto mainclients = c->mainClients(); - for (auto tmp : mainclients) - ret.append(tmp->effectWindow()); + EffectWindowList ret; + ret.reserve(mainclients.size()); + std::transform(std::cbegin(mainclients), std::cend(mainclients), + std::back_inserter(ret), + [](auto client) { return client->effectWindow(); }); return ret; } @@ -1818,9 +1822,12 @@ void EffectWindowImpl::unreferencePreviousWindowPixmap() EffectWindowList EffectWindowGroupImpl::members() const { + const auto memberList = group->members(); EffectWindowList ret; - for (Toplevel * c : group->members()) - ret.append(c->effectWindow()); + ret.reserve(memberList.size()); + std::transform(std::cbegin(memberList), std::cend(memberList), + std::back_inserter(ret), + [](auto toplevel) { return toplevel->effectWindow(); }); return ret; }