Improve use of QHash to minimize double hashing
Avoid looking up by key twice in a row in various locations, but instead using iterators and index lookup. Change-Id: I61a079115199ab9c041ad3a26d36b45ee3f775e0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
5cff7d2b67
commit
467b15a20c
|
|
@ -383,13 +383,11 @@ QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName,
|
|||
// Used to protect against potential recursions
|
||||
visited << themeName;
|
||||
|
||||
QIconTheme theme = themeList.value(themeName);
|
||||
QIconTheme &theme = themeList[themeName];
|
||||
if (!theme.isValid()) {
|
||||
theme = QIconTheme(themeName);
|
||||
if (!theme.isValid())
|
||||
theme = QIconTheme(fallbackTheme());
|
||||
|
||||
themeList.insert(themeName, theme);
|
||||
}
|
||||
|
||||
const QStringList contentDirs = theme.contentDirs();
|
||||
|
|
|
|||
|
|
@ -324,26 +324,23 @@ QPixmap *QPMCache::object(const QPixmapCache::Key &key) const
|
|||
|
||||
bool QPMCache::insert(const QString& key, const QPixmap &pixmap, int cost)
|
||||
{
|
||||
QPixmapCache::Key cacheKey;
|
||||
QPixmapCache::Key oldCacheKey = cacheKeys.value(key);
|
||||
QPixmapCache::Key &cacheKey = cacheKeys[key];
|
||||
//If for the same key we add already a pixmap we should delete it
|
||||
if (oldCacheKey.d) {
|
||||
QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(oldCacheKey);
|
||||
cacheKeys.remove(key);
|
||||
}
|
||||
if (cacheKey.d)
|
||||
QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(cacheKey);
|
||||
|
||||
//we create a new key the old one has been removed
|
||||
cacheKey = createKey();
|
||||
|
||||
bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost);
|
||||
if (success) {
|
||||
cacheKeys.insert(key, cacheKey);
|
||||
if (!theid) {
|
||||
theid = startTimer(flush_time);
|
||||
t = false;
|
||||
}
|
||||
} else {
|
||||
//Insertion failed we released the new allocated key
|
||||
cacheKeys.remove(key);
|
||||
releaseKey(cacheKey);
|
||||
}
|
||||
return success;
|
||||
|
|
@ -389,12 +386,12 @@ bool QPMCache::replace(const QPixmapCache::Key &key, const QPixmap &pixmap, int
|
|||
|
||||
bool QPMCache::remove(const QString &key)
|
||||
{
|
||||
QPixmapCache::Key cacheKey = cacheKeys.value(key);
|
||||
auto cacheKey = cacheKeys.constFind(key);
|
||||
//The key was not in the cache
|
||||
if (!cacheKey.d)
|
||||
if (cacheKey == cacheKeys.constEnd())
|
||||
return false;
|
||||
cacheKeys.remove(key);
|
||||
return QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(cacheKey);
|
||||
cacheKeys.erase(cacheKey);
|
||||
return QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(cacheKey.value());
|
||||
}
|
||||
|
||||
bool QPMCache::remove(const QPixmapCache::Key &key)
|
||||
|
|
|
|||
|
|
@ -848,14 +848,15 @@ QAbstractOpenGLFunctions *QOpenGLContext::versionFunctions(const QOpenGLVersionP
|
|||
|
||||
// Create object if suitable one not cached
|
||||
QAbstractOpenGLFunctions* funcs = 0;
|
||||
if (!d->versionFunctions.contains(vp)) {
|
||||
auto it = d->versionFunctions.constFind(vp);
|
||||
if (it == d->versionFunctions.constEnd()) {
|
||||
funcs = QOpenGLVersionFunctionsFactory::create(vp);
|
||||
if (funcs) {
|
||||
funcs->setOwningContext(this);
|
||||
d->versionFunctions.insert(vp, funcs);
|
||||
}
|
||||
} else {
|
||||
funcs = d->versionFunctions.value(vp);
|
||||
funcs = it.value();
|
||||
}
|
||||
|
||||
if (funcs && QOpenGLContext::currentContext() == this)
|
||||
|
|
|
|||
|
|
@ -320,8 +320,9 @@ void QFreetypeFace::release(const QFontEngine::FaceId &face_id)
|
|||
|
||||
cleanup();
|
||||
|
||||
if (freetypeData->faces.contains(face_id))
|
||||
freetypeData->faces.take(face_id);
|
||||
auto it = freetypeData->faces.constFind(face_id);
|
||||
if (it != freetypeData->faces.constEnd())
|
||||
freetypeData->faces.erase(it);
|
||||
|
||||
if (freetypeData->faces.isEmpty()) {
|
||||
FT_Done_FreeType(freetypeData->library);
|
||||
|
|
|
|||
|
|
@ -3409,8 +3409,7 @@ int QTextFormatCollection::indexForFormat(const QTextFormat &format)
|
|||
f.d = new QTextFormatPrivate;
|
||||
f.d->resolveFont(defaultFnt);
|
||||
|
||||
if (!hashes.contains(hash, idx))
|
||||
hashes.insert(hash, idx);
|
||||
hashes.insert(hash, idx);
|
||||
|
||||
} QT_CATCH(...) {
|
||||
formats.pop_back();
|
||||
|
|
|
|||
|
|
@ -1059,9 +1059,10 @@ QList<QGlyphRun> QTextLayout::glyphRuns(int from, int length) const
|
|||
QGlyphRun::GlyphRunFlags flags = glyphRun.flags();
|
||||
QPair<QFontEngine *, int> key(fontEngine, int(flags));
|
||||
// merge the glyph runs using the same font
|
||||
if (glyphRunHash.contains(key)) {
|
||||
QGlyphRun &oldGlyphRun = glyphRunHash[key];
|
||||
|
||||
QGlyphRun &oldGlyphRun = glyphRunHash[key];
|
||||
if (oldGlyphRun.isEmpty()) {
|
||||
oldGlyphRun = glyphRun;
|
||||
} else {
|
||||
QVector<quint32> indexes = oldGlyphRun.glyphIndexes();
|
||||
QVector<QPointF> positions = oldGlyphRun.positions();
|
||||
QRectF boundingRect = oldGlyphRun.boundingRect();
|
||||
|
|
@ -1073,8 +1074,6 @@ QList<QGlyphRun> QTextLayout::glyphRuns(int from, int length) const
|
|||
oldGlyphRun.setGlyphIndexes(indexes);
|
||||
oldGlyphRun.setPositions(positions);
|
||||
oldGlyphRun.setBoundingRect(boundingRect);
|
||||
} else {
|
||||
glyphRunHash[key] = glyphRun;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -524,10 +524,11 @@ namespace {
|
|||
|
||||
const void *key = *reinterpret_cast<void * const *>(fontFileReferenceKey);
|
||||
*fontFileStream = NULL;
|
||||
if (!m_fontDatas.contains(key))
|
||||
auto it = m_fontDatas.constFind(key);
|
||||
if (it == m_fontDatas.constEnd())
|
||||
return E_FAIL;
|
||||
|
||||
QByteArray fontData = m_fontDatas.value(key);
|
||||
QByteArray fontData = it.value();
|
||||
DirectWriteFontFileStream *stream = new DirectWriteFontFileStream(fontData);
|
||||
stream->AddRef();
|
||||
*fontFileStream = stream;
|
||||
|
|
|
|||
|
|
@ -486,10 +486,9 @@ QAccessibleInterface *QAccessibleTable::child(int logicalIndex) const
|
|||
if (!view()->model())
|
||||
return 0;
|
||||
|
||||
if (childToId.contains(logicalIndex)) {
|
||||
QAccessible::Id id = childToId.value(logicalIndex);
|
||||
return QAccessible::accessibleInterface(id);
|
||||
}
|
||||
auto id = childToId.constFind(logicalIndex);
|
||||
if (id != childToId.constEnd())
|
||||
return QAccessible::accessibleInterface(id.value());
|
||||
|
||||
int vHeader = verticalHeader() ? 1 : 0;
|
||||
int hHeader = horizontalHeader() ? 1 : 0;
|
||||
|
|
|
|||
|
|
@ -628,10 +628,10 @@ void QPixmapStyle::drawCachedPixmap(QPixmapStyle::ControlDescriptor control, con
|
|||
QPainter *p) const
|
||||
{
|
||||
Q_D(const QPixmapStyle);
|
||||
if (!d->descriptors.contains(control))
|
||||
auto descriptor = d->descriptors.constFind(control);
|
||||
if (descriptor == d->descriptors.constEnd())
|
||||
return;
|
||||
const QPixmapStyleDescriptor &desc = d->descriptors.value(control);
|
||||
const QPixmap pix = d->getCachedPixmap(control, desc, rect.size());
|
||||
const QPixmap pix = d->getCachedPixmap(control, descriptor.value(), rect.size());
|
||||
Q_ASSERT(!pix.isNull());
|
||||
p->drawPixmap(rect, pix);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue