From 7ee83dc5e425bfa2f7f3f92586bc4434da80634b Mon Sep 17 00:00:00 2001 From: Vlad Zagorodniy Date: Mon, 2 Jul 2018 10:26:58 +0300 Subject: [PATCH] Use std::find_if in EffectsHandlerImpl::isEffectLoaded Summary: Don't use raw loops. Use appropriate algorithm from STL to find out whether effect with the given name is loaded. (also, this change deletes duplicated logic) Reviewers: #kwin, broulik, romangg Reviewed By: #kwin, broulik, romangg Subscribers: broulik, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D13836 --- effects.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/effects.cpp b/effects.cpp index d48b9a2394..c01d8862ef 100644 --- a/effects.cpp +++ b/effects.cpp @@ -1369,20 +1369,15 @@ void EffectsHandlerImpl::reconfigureEffect(const QString& name) bool EffectsHandlerImpl::isEffectLoaded(const QString& name) const { - for (QVector< EffectPair >::const_iterator it = loaded_effects.constBegin(); it != loaded_effects.constEnd(); ++it) - if ((*it).first == name) - return true; - - return false; + auto it = std::find_if(loaded_effects.constBegin(), loaded_effects.constEnd(), + [&name](const EffectPair &pair) { return pair.first == name; }); + return it != loaded_effects.constEnd(); } bool EffectsHandlerImpl::isEffectSupported(const QString &name) { - // if the effect is loaded, it is obviously supported - auto it = std::find_if(loaded_effects.constBegin(), loaded_effects.constEnd(), [name](const EffectPair &pair) { - return pair.first == name; - }); - if (it != loaded_effects.constEnd()) { + // If the effect is loaded, it is obviously supported. + if (isEffectLoaded(name)) { return true; }