Remove container 2x lookups

Instead of checking for existance and then getting the value. Look it up
once and use the value if avaliable.
This saves us one hash look-up per execution which can be considerable,
especially in the case of findElementRect.
This commit is contained in:
Aleix Pol 2021-07-01 03:21:42 +02:00 committed by Aleix Pol Gonzalez
parent 53d1bf4577
commit d809e9e4dc
1 changed files with 5 additions and 3 deletions

View File

@ -188,7 +188,8 @@ bool SvgRectsCache::findElementRect(uint id, const QString &filePath, QRectF &re
auto it = m_localRectCache.find(id);
if (it == m_localRectCache.end()) {
if (m_invalidElements.contains(filePath) && m_invalidElements[filePath].contains(id)) {
auto elements = m_invalidElements.value(filePath);
if (elements.contains(id)) {
rect = QRectF();
return true;
}
@ -243,7 +244,8 @@ QList<QSize> SvgRectsCache::sizeHintsForId(const QString &path, const QString &i
{
const QString pathId = path % id;
if (!m_sizeHintsForId.contains(pathId)) {
auto it = m_sizeHintsForId.constFind(pathId);
if (it == m_sizeHintsForId.constEnd()) {
KConfigGroup imageGroup(m_svgElementsCache, path);
const QStringList &encoded = imageGroup.readEntry(id, QStringList());
QList<QSize> sizes;
@ -261,7 +263,7 @@ QList<QSize> SvgRectsCache::sizeHintsForId(const QString &path, const QString &i
return sizes;
}
return m_sizeHintsForId.value(pathId);
return *it;
}
void SvgRectsCache::insertSizeHintForId(const QString &path, const QString &id, const QSize &size)