diff --git a/effects/effect_builtins.cpp b/effects/effect_builtins.cpp index 60fe22b286..f1fda6f547 100644 --- a/effects/effect_builtins.cpp +++ b/effects/effect_builtins.cpp @@ -84,7 +84,9 @@ inline Effect *createHelper() return new T(); } -static const QVector s_effectData = { +static const QVector &effectData() +{ + static const QVector s_effectData = { { QString(), QString(), @@ -683,7 +685,9 @@ EFFECT_FALLBACK #endif EFFECT_FALLBACK } -}; + }; + return s_effectData; +} static inline int index(BuiltInEffect effect) { @@ -692,21 +696,21 @@ static inline int index(BuiltInEffect effect) Effect *create(BuiltInEffect effect) { - const EffectData &effectData = s_effectData.at(index(effect)); - if (effectData.createFunction == nullptr) { + const EffectData &data = effectData(effect); + if (data.createFunction == nullptr) { return nullptr; } - return effectData.createFunction(); + return data.createFunction(); } bool available(const QString &name) { - auto it = std::find_if(s_effectData.begin(), s_effectData.end(), + auto it = std::find_if(effectData().begin(), effectData().end(), [name](const EffectData &data) { return data.name == name; } ); - return it != s_effectData.end(); + return it != effectData().end(); } bool supported(BuiltInEffect effect) @@ -714,11 +718,11 @@ bool supported(BuiltInEffect effect) if (effect == BuiltInEffect::Invalid) { return false; } - const EffectData &effectData = s_effectData.at(index(effect)); - if (effectData.supportedFunction == nullptr) { + const EffectData &data = effectData(effect); + if (data.supportedFunction == nullptr) { return true; } - return effectData.supportedFunction(); + return data.supportedFunction(); } bool checkEnabledByDefault(BuiltInEffect effect) @@ -726,23 +730,22 @@ bool checkEnabledByDefault(BuiltInEffect effect) if (effect == BuiltInEffect::Invalid) { return false; } - const EffectData &effectData = s_effectData.at(index(effect)); - if (effectData.enabledFunction == nullptr) { + const EffectData &data = effectData(effect); + if (data.enabledFunction == nullptr) { return true; } - return effectData.enabledFunction(); + return data.enabledFunction(); } bool enabledByDefault(BuiltInEffect effect) { - const EffectData &effectData = s_effectData.at(index(effect)); - return effectData.enabled; + return effectData(effect).enabled; } QStringList availableEffectNames() { QStringList result; - for (const EffectData &data : s_effectData) { + for (const EffectData &data : effectData()) { if (data.name.isEmpty()) { continue; } @@ -762,25 +765,25 @@ QList< BuiltInEffect > availableEffects() BuiltInEffect builtInForName(const QString &name) { - auto it = std::find_if(s_effectData.begin(), s_effectData.end(), + auto it = std::find_if(effectData().begin(), effectData().end(), [name](const EffectData &data) { return data.name == name; } ); - if (it == s_effectData.end()) { + if (it == effectData().end()) { return BuiltInEffect::Invalid; } - return BuiltInEffect(std::distance(s_effectData.begin(), it)); + return BuiltInEffect(std::distance(effectData().begin(), it)); } QString nameForEffect(BuiltInEffect effect) { - return s_effectData.at(index(effect)).name; + return effectData(effect).name; } const EffectData &effectData(BuiltInEffect effect) { - return s_effectData.at(index(effect)); + return effectData().at(index(effect)); } } // BuiltInEffects