From 18367d0a1182d22f23fa1414432e52b429ae9fa8 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Mon, 16 Oct 2023 21:23:51 +0300 Subject: [PATCH] qmimeglobpattern: port some methods to QSV It's private API, so it's safe Change-Id: Ibf35262117c4ce4a1e548fff814a6e7bea362309 Reviewed-by: David Faure --- src/corelib/mimetypes/qmimeglobpattern.cpp | 6 +++--- src/corelib/mimetypes/qmimeglobpattern_p.h | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/corelib/mimetypes/qmimeglobpattern.cpp b/src/corelib/mimetypes/qmimeglobpattern.cpp index 80be35e8ea..d50787a0be 100644 --- a/src/corelib/mimetypes/qmimeglobpattern.cpp +++ b/src/corelib/mimetypes/qmimeglobpattern.cpp @@ -58,7 +58,7 @@ void QMimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const Q } } -QMimeGlobPattern::PatternType QMimeGlobPattern::detectPatternType(const QString &pattern) const +QMimeGlobPattern::PatternType QMimeGlobPattern::detectPatternType(QStringView pattern) const { const qsizetype patternLength = pattern.size(); if (!patternLength) @@ -163,7 +163,7 @@ bool QMimeGlobPattern::matchFileName(const QString &inputFileName) const return false; } -static bool isSimplePattern(const QString &pattern) +static bool isSimplePattern(QStringView pattern) { // starts with "*.", has no other '*' return pattern.lastIndexOf(u'*') == 0 @@ -175,7 +175,7 @@ static bool isSimplePattern(const QString &pattern) ; } -static bool isFastPattern(const QString &pattern) +static bool isFastPattern(QStringView pattern) { // starts with "*.", has no other '*' and no other '.' return pattern.lastIndexOf(u'*') == 0 diff --git a/src/corelib/mimetypes/qmimeglobpattern_p.h b/src/corelib/mimetypes/qmimeglobpattern_p.h index 4064700e39..b4316355ba 100644 --- a/src/corelib/mimetypes/qmimeglobpattern_p.h +++ b/src/corelib/mimetypes/qmimeglobpattern_p.h @@ -22,6 +22,8 @@ QT_REQUIRE_CONFIG(mimetype); #include #include +#include + QT_BEGIN_NAMESPACE struct QMimeGlobMatchResult @@ -77,7 +79,7 @@ private: AnimPattern, // special handling for "*.anim[1-9j]" pattern OtherPattern }; - PatternType detectPatternType(const QString &pattern) const; + PatternType detectPatternType(QStringView pattern) const; QString m_pattern; QString m_mimeType; @@ -92,22 +94,20 @@ using AddMatchFilterFunc = std::function; class QMimeGlobPatternList : public QList { public: - bool hasPattern(const QString &mimeType, const QString &pattern) const + bool hasPattern(QStringView mimeType, QStringView pattern) const { - const_iterator it = begin(); - const const_iterator myend = end(); - for (; it != myend; ++it) - if ((*it).pattern() == pattern && (*it).mimeType() == mimeType) - return true; - return false; + auto matchesMimeAndPattern = [mimeType, pattern](const QMimeGlobPattern &e) { + return e.pattern() == pattern && e.mimeType() == mimeType; + }; + return std::any_of(begin(), end(), matchesMimeAndPattern); } /*! "noglobs" is very rare occurrence, so it's ok if it's slow */ - void removeMimeType(const QString &mimeType) + void removeMimeType(QStringView mimeType) { - auto isMimeTypeEqual = [&mimeType](const QMimeGlobPattern &pattern) { + auto isMimeTypeEqual = [mimeType](const QMimeGlobPattern &pattern) { return pattern.mimeType() == mimeType; }; removeIf(isMimeTypeEqual);