diff options
author | Igor Kushnir <igorkuo@gmail.com> | 2021-12-12 12:32:45 +0200 |
---|---|---|
committer | Igor Kushnir <igorkuo@gmail.com> | 2021-12-21 21:21:50 +0200 |
commit | 0dbbda670d1e9f79d85edc1599315943d9eec33a (patch) | |
tree | bd33abbddc0fba2aea43aaccb60705ae06cf6404 /src/corelib/mimetypes/qmimedatabase_p.h | |
parent | 11409f4c023d7a9596ab5c0ca98256f650be9a90 (diff) |
QMimeDatabasePrivate: deduplicate QStringLiteral
defaultMimeType() cannot be moved out of the class and defined in
qmimedatabase.cpp, because it is called from QMimeType::isDefault() in
qmimetype.cpp.
Return m_defaultMimeType constant by reference rather than by value from
the inline helper function. This eliminates useless copying of QString
when calling code needs only a reference, and so improves performance.
Even though m_defaultMimeType is initialized with a QStringLiteral and
its QArrayDataPointer has d == nullptr, QArrayDataPointer's ref() and
deref() still have to compare d with nullptr to decide that no reference
count manipulation is needed. Compilers might be unable to reorder these
checks with surrounding code because they guard reference count
manipulation. Branch misprediction could further harm performance.
Optimizing these checks out can be difficult for compilers.
Change-Id: I3ffa0fdc5ad948452301dd9688073b5323a7983b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/mimetypes/qmimedatabase_p.h')
-rw-r--r-- | src/corelib/mimetypes/qmimedatabase_p.h | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/corelib/mimetypes/qmimedatabase_p.h b/src/corelib/mimetypes/qmimedatabase_p.h index ba5997e943..4f19c9b9da 100644 --- a/src/corelib/mimetypes/qmimedatabase_p.h +++ b/src/corelib/mimetypes/qmimedatabase_p.h @@ -84,7 +84,7 @@ public: static QMimeDatabasePrivate *instance(); - inline QString defaultMimeType() const { return m_defaultMimeType; } + const QString &defaultMimeType() const { return m_defaultMimeType; } bool inherits(const QString &mime, const QString &parent); @@ -114,12 +114,13 @@ private: const Providers &providers(); bool shouldCheck(); void loadProviders(); + QString fallbackParent(const QString &mimeTypeName) const; + const QString m_defaultMimeType; mutable Providers m_providers; QElapsedTimer m_lastCheck; public: - const QString m_defaultMimeType; QMutex mutex; }; |