QMimeBinaryProvider: cut out the QMap middle-man
In Qt 6, QMap is just a shared pointer to a std::map. QMimeBinaryProvider::m_mimetypeExtra is never copied, though, so the implicit sharing that QMap adds on top of std::map is useless. Use the underlying std::map directly. Yes, the std::map API is a bit raw around the edges (std::pair value_type), but we're professionals here. Saves more than 1.7KiB in TEXT size on optimized AMD64 GCC 11 C++20 Linux builds. As a drive-by, cut out the insertIt temporary, too, and assign directly to `it`. Change-Id: If3fd98a7e7017909d00b8725f8c252b19459d5b6 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: David Faure <david.faure@kdab.com>bb10
parent
38c62c5851
commit
e3cc87c5f4
|
|
@ -9,7 +9,6 @@
|
|||
#include <qstandardpaths.h>
|
||||
#include "qmimemagicrulematcher_p.h"
|
||||
|
||||
#include <QMap>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QBuffer>
|
||||
#include <QDir>
|
||||
|
|
@ -488,30 +487,24 @@ void QMimeBinaryProvider::addAllMimeTypes(QList<QMimeType> &result)
|
|||
QMimeTypePrivate::LocaleHash QMimeBinaryProvider::localeComments(const QString &name)
|
||||
{
|
||||
MimeTypeExtraMap::const_iterator it = loadMimeTypeExtra(name);
|
||||
if (it != m_mimetypeExtra.constEnd()) {
|
||||
const MimeTypeExtra &e = it.value();
|
||||
return e.localeComments;
|
||||
}
|
||||
if (it != m_mimetypeExtra.cend())
|
||||
return it->second.localeComments;
|
||||
return {};
|
||||
}
|
||||
|
||||
bool QMimeBinaryProvider::hasGlobDeleteAll(const QString &name)
|
||||
{
|
||||
MimeTypeExtraMap::const_iterator it = loadMimeTypeExtra(name);
|
||||
if (it != m_mimetypeExtra.constEnd()) {
|
||||
const MimeTypeExtra &e = it.value();
|
||||
return e.hasGlobDeleteAll;
|
||||
}
|
||||
if (it != m_mimetypeExtra.cend())
|
||||
return it->second.hasGlobDeleteAll;
|
||||
return {};
|
||||
}
|
||||
|
||||
QStringList QMimeBinaryProvider::globPatterns(const QString &name)
|
||||
{
|
||||
MimeTypeExtraMap::const_iterator it = loadMimeTypeExtra(name);
|
||||
if (it != m_mimetypeExtra.constEnd()) {
|
||||
const MimeTypeExtra &e = it.value();
|
||||
return e.globPatterns;
|
||||
}
|
||||
if (it != m_mimetypeExtra.cend())
|
||||
return it->second.globPatterns;
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
@ -519,8 +512,8 @@ QMimeBinaryProvider::MimeTypeExtraMap::const_iterator
|
|||
QMimeBinaryProvider::loadMimeTypeExtra(const QString &mimeName)
|
||||
{
|
||||
#if QT_CONFIG(xmlstreamreader)
|
||||
auto it = m_mimetypeExtra.constFind(mimeName);
|
||||
if (it == m_mimetypeExtra.constEnd()) {
|
||||
auto it = m_mimetypeExtra.find(mimeName);
|
||||
if (it == m_mimetypeExtra.cend()) {
|
||||
// load comment and globPatterns
|
||||
|
||||
// shared-mime-info since 1.3 lowercases the xml files
|
||||
|
|
@ -530,21 +523,20 @@ QMimeBinaryProvider::loadMimeTypeExtra(const QString &mimeName)
|
|||
|
||||
QFile qfile(mimeFile);
|
||||
if (!qfile.open(QFile::ReadOnly))
|
||||
return m_mimetypeExtra.constEnd();
|
||||
return m_mimetypeExtra.cend();
|
||||
|
||||
auto insertIt = m_mimetypeExtra.insert(mimeName, MimeTypeExtra{});
|
||||
it = insertIt;
|
||||
MimeTypeExtra &extra = insertIt.value();
|
||||
it = m_mimetypeExtra.try_emplace(mimeName).first;
|
||||
MimeTypeExtra &extra = it->second;
|
||||
QString mainPattern;
|
||||
|
||||
QXmlStreamReader xml(&qfile);
|
||||
if (xml.readNextStartElement()) {
|
||||
if (xml.name() != "mime-type"_L1) {
|
||||
return m_mimetypeExtra.constEnd();
|
||||
return m_mimetypeExtra.cend();
|
||||
}
|
||||
const auto name = xml.attributes().value("type"_L1);
|
||||
if (name.isEmpty())
|
||||
return m_mimetypeExtra.constEnd();
|
||||
return m_mimetypeExtra.cend();
|
||||
if (name.compare(mimeName, Qt::CaseInsensitive))
|
||||
qWarning() << "Got name" << name << "in file" << mimeFile << "expected" << mimeName;
|
||||
|
||||
|
|
@ -585,7 +577,7 @@ QMimeBinaryProvider::loadMimeTypeExtra(const QString &mimeName)
|
|||
#else
|
||||
Q_UNUSED(mimeName);
|
||||
qWarning("Cannot load mime type since QXmlStreamReader is not available.");
|
||||
return m_mimetypeExtra.constEnd();
|
||||
return m_mimetypeExtra.cend();
|
||||
#endif // feature xmlstreamreader
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ QT_REQUIRE_CONFIG(mimetype);
|
|||
#include "qmimeglobpattern_p.h"
|
||||
#include <QtCore/qdatetime.h>
|
||||
#include <QtCore/qset.h>
|
||||
#include <QtCore/qmap.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -123,7 +124,7 @@ private:
|
|||
QStringList globPatterns;
|
||||
bool hasGlobDeleteAll = false;
|
||||
};
|
||||
using MimeTypeExtraMap = QMap<QString, MimeTypeExtra>;
|
||||
using MimeTypeExtraMap = std::map<QString, MimeTypeExtra>;
|
||||
MimeTypeExtraMap m_mimetypeExtra;
|
||||
|
||||
MimeTypeExtraMap::const_iterator loadMimeTypeExtra(const QString &mimeName);
|
||||
|
|
|
|||
Loading…
Reference in New Issue