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:
parent
53d1bf4577
commit
d809e9e4dc
@ -188,7 +188,8 @@ bool SvgRectsCache::findElementRect(uint id, const QString &filePath, QRectF &re
|
|||||||
auto it = m_localRectCache.find(id);
|
auto it = m_localRectCache.find(id);
|
||||||
|
|
||||||
if (it == m_localRectCache.end()) {
|
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();
|
rect = QRectF();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -243,7 +244,8 @@ QList<QSize> SvgRectsCache::sizeHintsForId(const QString &path, const QString &i
|
|||||||
{
|
{
|
||||||
const QString pathId = path % id;
|
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);
|
KConfigGroup imageGroup(m_svgElementsCache, path);
|
||||||
const QStringList &encoded = imageGroup.readEntry(id, QStringList());
|
const QStringList &encoded = imageGroup.readEntry(id, QStringList());
|
||||||
QList<QSize> sizes;
|
QList<QSize> sizes;
|
||||||
@ -261,7 +263,7 @@ QList<QSize> SvgRectsCache::sizeHintsForId(const QString &path, const QString &i
|
|||||||
return sizes;
|
return sizes;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_sizeHintsForId.value(pathId);
|
return *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SvgRectsCache::insertSizeHintForId(const QString &path, const QString &id, const QSize &size)
|
void SvgRectsCache::insertSizeHintForId(const QString &path, const QString &id, const QSize &size)
|
||||||
|
Loading…
Reference in New Issue
Block a user