Skip to content

Commit 7546168

Browse files
mimetypes: keep track of whether extra mimetype exists
In the BinaryProvider backend each mimetype optionally has additional data in an XML file. For each mimetype this data is cached in m_mimetypeExtra. However, if a mimetype does not have any additional data this code returns early without caching anything. This causes an additional access and open call for every mimetype for each lookup of globPatterns. Given we have typically have hundreds of mimetypes and applications may need to look up thousands of files this becomes a very hot path that should not be making system calls after the first time. This patch should improve performance but not make any behavioural changes. All callers treat an invalid iterator the same as the default MimeTypeExtraMap. Change-Id: Ibe415ec4e70198655d7a6ad610664fe54e3b9215 Reviewed-by: Thiago Macieira <[email protected]> Reviewed-by: David Faure <[email protected]>
1 parent e27d5fc commit 7546168

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/corelib/mimetypes/qmimeprovider.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,8 @@ QMimeBinaryProvider::MimeTypeExtraMap::const_iterator
512512
QMimeBinaryProvider::loadMimeTypeExtra(const QString &mimeName)
513513
{
514514
#if QT_CONFIG(xmlstreamreader)
515-
auto it = m_mimetypeExtra.find(mimeName);
516-
if (it == m_mimetypeExtra.cend()) {
515+
auto [it, insertionOccurred] = m_mimetypeExtra.try_emplace(mimeName);
516+
if (insertionOccurred) {
517517
// load comment and globPatterns
518518

519519
// shared-mime-info since 1.3 lowercases the xml files
@@ -523,9 +523,8 @@ QMimeBinaryProvider::loadMimeTypeExtra(const QString &mimeName)
523523

524524
QFile qfile(mimeFile);
525525
if (!qfile.open(QFile::ReadOnly))
526-
return m_mimetypeExtra.cend();
526+
return it;
527527

528-
it = m_mimetypeExtra.try_emplace(mimeName).first;
529528
MimeTypeExtra &extra = it->second;
530529
QString mainPattern;
531530

0 commit comments

Comments
 (0)