diff options
author | Anton Kudryavtsev <a.kudryavtsev@netris.ru> | 2016-03-31 12:01:59 +0300 |
---|---|---|
committer | Anton Kudryavtsev <a.kudryavtsev@netris.ru> | 2016-07-02 07:39:06 +0000 |
commit | 6662919ecde901771d9641fd732aa0735ebb39e6 (patch) | |
tree | 449752f7d9582cd685d81829e0e2245b0f9a0ece /src/corelib/mimetypes | |
parent | 2185b2f054ddae0fc67b8799b3561c57729f1cd7 (diff) |
CoreLib: use QStringRef to optimize memory allocation
Replace substring functions that return QString with
corresponding functions that return QStringRef where
it's possible.
Create QString from QStringRef only where necessary.
Change-Id: Id9ea11b16947220cd27787c0b529de62d10b6c26
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/mimetypes')
-rw-r--r-- | src/corelib/mimetypes/qmimeglobpattern.cpp | 2 | ||||
-rw-r--r-- | src/corelib/mimetypes/qmimeprovider.cpp | 5 | ||||
-rw-r--r-- | src/corelib/mimetypes/qmimetype.cpp | 9 |
3 files changed, 9 insertions, 7 deletions
diff --git a/src/corelib/mimetypes/qmimeglobpattern.cpp b/src/corelib/mimetypes/qmimeglobpattern.cpp index 94be5385f3..568f9bf4de 100644 --- a/src/corelib/mimetypes/qmimeglobpattern.cpp +++ b/src/corelib/mimetypes/qmimeglobpattern.cpp @@ -124,7 +124,7 @@ bool QMimeGlobPattern::matchFileName(const QString &inputFilename) const if (starCount == 1 && m_pattern.at(pattern_len - 1) == QLatin1Char('*')) { if (len + 1 < pattern_len) return false; if (m_pattern.at(0) == QLatin1Char('*')) - return filename.indexOf(m_pattern.mid(1, pattern_len - 2)) != -1; + return filename.indexOf(m_pattern.midRef(1, pattern_len - 2)) != -1; const QChar *c1 = m_pattern.unicode(); const QChar *c2 = filename.unicode(); diff --git a/src/corelib/mimetypes/qmimeprovider.cpp b/src/corelib/mimetypes/qmimeprovider.cpp index dc6eb05d9a..e72f9a30d0 100644 --- a/src/corelib/mimetypes/qmimeprovider.cpp +++ b/src/corelib/mimetypes/qmimeprovider.cpp @@ -63,7 +63,7 @@ QT_BEGIN_NAMESPACE static QString fallbackParent(const QString &mimeTypeName) { - const QString myGroup = mimeTypeName.left(mimeTypeName.indexOf(QLatin1Char('/'))); + const QStringRef myGroup = mimeTypeName.leftRef(mimeTypeName.indexOf(QLatin1Char('/'))); // All text/* types are subclasses of text/plain. if (myGroup == QLatin1String("text") && mimeTypeName != QLatin1String("text/plain")) return QLatin1String("text/plain"); @@ -363,7 +363,8 @@ bool QMimeBinaryProvider::matchSuffixTree(QMimeGlobMatchResult &result, QMimeBin const int weight = flagsAndWeight & 0xff; const bool caseSensitive = flagsAndWeight & 0x100; if (caseSensitiveCheck || !caseSensitive) { - result.addMatch(QLatin1String(mimeType), weight, QLatin1Char('*') + fileName.mid(charPos+1)); + result.addMatch(QLatin1String(mimeType), weight, + QLatin1Char('*') + fileName.midRef(charPos + 1)); success = true; } } diff --git a/src/corelib/mimetypes/qmimetype.cpp b/src/corelib/mimetypes/qmimetype.cpp index 80b6a76ecc..5d18b67e8d 100644 --- a/src/corelib/mimetypes/qmimetype.cpp +++ b/src/corelib/mimetypes/qmimetype.cpp @@ -286,11 +286,12 @@ QString QMimeType::genericIconName() const // then the mimetype is used to generate the generic icon by using the top-level // media type (e.g. "video" in "video/ogg") and appending "-x-generic" // (i.e. "video-x-generic" in the previous example). - QString group = name(); - const int slashindex = group.indexOf(QLatin1Char('/')); + const QString group = name(); + QStringRef groupRef(&group); + const int slashindex = groupRef.indexOf(QLatin1Char('/')); if (slashindex != -1) - group = group.left(slashindex); - return group + QLatin1String("-x-generic"); + groupRef = groupRef.left(slashindex); + return groupRef + QLatin1String("-x-generic"); } return d->genericIconName; } |