Skip to content

Commit

Permalink
QIcon::addFile: don't use QMimeDatabase for every PNG being loaded
Browse files Browse the repository at this point in the history
Commit 710ff39 introduced this fallback code for the case where the
extension was empty. Let's make it happen only in that case, so that the
much more common case of "foo.png" doesn't go through
iconEngineFromSuffix twice, nor through QMimeDatabase (which has to load
and parse an XML file in order to determine preferredSuffix(),
unfortunately).

Found using heaptrack.

Change-Id: Iab6b71e1fa23916029c9e2ba25447a12d70f88a5
Reviewed-by: Friedemann Kleint <[email protected]>
  • Loading branch information
dfaure-kdab committed Oct 4, 2018
1 parent 4f4a331 commit 80cc6bc
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/gui/image/qicon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1078,11 +1078,12 @@ void QIcon::addFile(const QString &fileName, const QSize &size, Mode mode, State
if (!d) {

QFileInfo info(fileName);
QIconEngine *engine = iconEngineFromSuffix(fileName, info.suffix());
QString suffix = info.suffix();
#ifndef QT_NO_MIMETYPE
if (!engine)
engine = iconEngineFromSuffix(fileName, QMimeDatabase().mimeTypeForFile(info).preferredSuffix());
if (suffix.isEmpty())
suffix = QMimeDatabase().mimeTypeForFile(info).preferredSuffix(); // determination from contents
#endif // !QT_NO_MIMETYPE
QIconEngine *engine = iconEngineFromSuffix(fileName, suffix);
d = new QIconPrivate(engine ? engine : new QPixmapIconEngine);
}

Expand Down

0 comments on commit 80cc6bc

Please sign in to comment.