From 7a5c59f21fc68e3020c2acf0cd50146ef6a61005 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 23 Nov 2020 15:55:55 +0100 Subject: Simplify ShaderEffect's internal shaderInfoCache Change-Id: Id542b473c1596f9933cdef747f7fe329988618d4 Reviewed-by: Andy Nichols --- src/quick/items/qquickshadereffect.cpp | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) (limited to 'src/quick/items') diff --git a/src/quick/items/qquickshadereffect.cpp b/src/quick/items/qquickshadereffect.cpp index ec05cf5ca1..b4d9f9f69d 100644 --- a/src/quick/items/qquickshadereffect.cpp +++ b/src/quick/items/qquickshadereffect.cpp @@ -1155,27 +1155,8 @@ static inline QVariant getValueFromProperty(QObject *item, const QMetaObject *it return value; } -struct ShaderInfoCache -{ - bool contains(const QUrl &key) const - { - return m_shaderInfoCache.contains(key); - } - - QSGGuiThreadShaderEffectManager::ShaderInfo value(const QUrl &key) const - { - return m_shaderInfoCache.value(key); - } - - void insert(const QUrl &key, const QSGGuiThreadShaderEffectManager::ShaderInfo &value) - { - m_shaderInfoCache.insert(key, value); - } - - QHash m_shaderInfoCache; -}; - -Q_GLOBAL_STATIC(ShaderInfoCache, shaderInfoCache) +using QQuickShaderInfoCache = QHash; +Q_GLOBAL_STATIC(QQuickShaderInfoCache, shaderInfoCache) bool QQuickShaderEffectImpl::updateShader(Shader shaderType, const QUrl &fileUrl) { @@ -1193,8 +1174,9 @@ bool QQuickShaderEffectImpl::updateShader(Shader shaderType, const QUrl &fileUrl if (!fileUrl.isEmpty()) { const QQmlContext *context = qmlContext(m_item); const QUrl loadUrl = context ? context->resolvedUrl(fileUrl) : fileUrl; - if (shaderInfoCache()->contains(loadUrl)) { - m_shaders[shaderType].shaderInfo = shaderInfoCache()->value(loadUrl); + auto it = shaderInfoCache()->constFind(loadUrl); + if (it != shaderInfoCache()->cend()) { + m_shaders[shaderType].shaderInfo = *it; m_shaders[shaderType].hasShaderCode = true; } else { // Each prepareShaderCode call needs its own work area, hence the -- cgit v1.2.3