SvgRectsCache: do not query elements twice

I was looking into why there is so much time spent here for the logout
greeter that only has buttons. It seems like we were querying the cache
file every time even though we already have separate code that checks
whether our information is valid.

As I started looking into it, ::loadImageFromCache was %25 of the CPU
time. After this patch it's short of 1%.
This commit is contained in:
Aleix Pol 2021-06-19 02:57:52 +02:00
parent 44a8e6c1ee
commit b0f8bff4ca
1 changed files with 11 additions and 8 deletions

View File

@ -217,15 +217,18 @@ void SvgRectsCache::loadImageFromCache(const QString &path, uint lastModified)
return;
}
auto list = imageGroup.readEntry("Invalidelements", QList<unsigned int>());
m_invalidElements[path] = QSet<unsigned int>(list.begin(), list.end());
auto &elements = m_invalidElements[path];
if (elements.isEmpty()) {
auto list = imageGroup.readEntry("Invalidelements", QList<unsigned int>());
m_invalidElements[path] = QSet<unsigned int>(list.begin(), list.end());
for (const auto &key : imageGroup.keyList()) {
bool ok = false;
uint keyUInt = key.toUInt(&ok);
if (ok) {
const QRectF rect = imageGroup.readEntry(key, QRectF());
m_localRectCache.insert(keyUInt, rect);
for (const auto &key : imageGroup.keyList()) {
bool ok = false;
uint keyUInt = key.toUInt(&ok);
if (ok) {
const QRectF rect = imageGroup.readEntry(key, QRectF());
m_localRectCache.insert(keyUInt, rect);
}
}
}
}