From 0be60cad2f21df8881500a367a612656a90aa3c9 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Tue, 27 Aug 2024 14:11:39 +0200 Subject: [PATCH] Update mime database from Qt qtbase/c1e1d133c47f6cbeee045dcec0dfe7c68d5bef34 mimetypes/: port to qsizetype Change-Id: I4ec76cc3af25efdadd31cb6d58235f0a55bf321a Reviewed-by: Jarek Kobus --- src/libs/utils/mimetypes2/mimedatabase.cpp | 2 +- src/libs/utils/mimetypes2/mimeglobpattern.cpp | 23 ++++++++----------- src/libs/utils/mimetypes2/mimeglobpattern_p.h | 7 +++--- src/libs/utils/mimetypes2/mimemagicrule.cpp | 10 ++++---- src/libs/utils/mimetypes2/mimemagicrule_p.h | 4 +++- src/libs/utils/mimetypes2/mimeprovider.cpp | 4 ++-- src/libs/utils/mimetypes2/mimeprovider_p.h | 2 +- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/libs/utils/mimetypes2/mimedatabase.cpp b/src/libs/utils/mimetypes2/mimedatabase.cpp index d44e769f17b..b68f982a09b 100644 --- a/src/libs/utils/mimetypes2/mimedatabase.cpp +++ b/src/libs/utils/mimetypes2/mimedatabase.cpp @@ -735,7 +735,7 @@ QList MimeDatabase::mimeTypesForFileName(const QString &fileName) cons QString MimeDatabase::suffixForFileName(const QString &fileName) const { QMutexLocker locker(&d->mutex); - const int suffixLength = d->findByFileName(fileName).m_knownSuffixLength; + const qsizetype suffixLength = d->findByFileName(fileName).m_knownSuffixLength; return fileName.right(suffixLength); } diff --git a/src/libs/utils/mimetypes2/mimeglobpattern.cpp b/src/libs/utils/mimetypes2/mimeglobpattern.cpp index 5921f2718d3..8d4af993103 100644 --- a/src/libs/utils/mimetypes2/mimeglobpattern.cpp +++ b/src/libs/utils/mimetypes2/mimeglobpattern.cpp @@ -22,7 +22,8 @@ namespace Utils { Handles glob weights, and preferring longer matches over shorter matches. */ -void MimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const QString &pattern, int knownSuffixLength) +void MimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const QString &pattern, + qsizetype knownSuffixLength) { if (m_allMatchingMimeTypes.contains(mimeType)) return; @@ -59,11 +60,11 @@ void MimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const QS MimeGlobPattern::PatternType MimeGlobPattern::detectPatternType(const QString &pattern) const { - const int patternLength = pattern.size(); + const qsizetype patternLength = pattern.size(); if (!patternLength) return OtherPattern; - const int starCount = pattern.count(u'*'); + const qsizetype starCount = pattern.count(u'*'); const bool hasSquareBracket = pattern.indexOf(u'[') != -1; const bool hasQuestionMark = pattern.indexOf(u'?') != -1; @@ -108,10 +109,10 @@ bool MimeGlobPattern::matchFileName(const QString &inputFileName) const const QString fileName = m_caseSensitivity == Qt::CaseInsensitive ? inputFileName.toLower() : inputFileName; - const int patternLength = m_pattern.size(); + const qsizetype patternLength = m_pattern.size(); if (!patternLength) return false; - const int fileNameLength = fileName.size(); + const qsizetype fileNameLength = fileName.size(); switch (m_patternType) { case SuffixPattern: { @@ -224,16 +225,12 @@ void MimeGlobPatternList::match(MimeGlobMatchResult &result, const QString &fileName, const QSet &ignoreMimeTypes) const { - - MimeGlobPatternList::const_iterator it = this->constBegin(); - const MimeGlobPatternList::const_iterator endIt = this->constEnd(); - for (; it != endIt; ++it) { - const MimeGlobPattern &glob = *it; + for (const MimeGlobPattern &glob : *this) { if (ignoreMimeTypes.contains(glob.mimeType())) continue; if (glob.matchFileName(fileName)) { const QString pattern = glob.pattern(); - const int suffixLen = isSimplePattern(pattern) ? pattern.size() - 2 : 0; + const qsizetype suffixLen = isSimplePattern(pattern) ? pattern.size() - strlen("*.") : 0; result.addMatch(glob.mimeType(), glob.weight(), pattern, suffixLen); } } @@ -248,9 +245,9 @@ void MimeAllGlobPatterns::matchingGlobs(const QString &fileName, // Now use the "fast patterns" dict, for simple *.foo patterns with weight 50 // (which is most of them, so this optimization is definitely worth it) - const int lastDot = fileName.lastIndexOf(u'.'); + const qsizetype lastDot = fileName.lastIndexOf(u'.'); if (lastDot != -1) { // if no '.', skip the extension lookup - const int ext_len = fileName.length() - lastDot - 1; + const qsizetype ext_len = fileName.length() - lastDot - 1; const QString simpleExtension = fileName.right(ext_len).toLower(); // (toLower because fast patterns are always case-insensitive and saved as lowercase) diff --git a/src/libs/utils/mimetypes2/mimeglobpattern_p.h b/src/libs/utils/mimetypes2/mimeglobpattern_p.h index c1191dffd8a..f57a2801822 100644 --- a/src/libs/utils/mimetypes2/mimeglobpattern_p.h +++ b/src/libs/utils/mimetypes2/mimeglobpattern_p.h @@ -21,13 +21,14 @@ namespace Utils { struct MimeGlobMatchResult { - void addMatch(const QString &mimeType, int weight, const QString &pattern, int knownSuffixLength = 0); + void addMatch(const QString &mimeType, int weight, const QString &pattern, + qsizetype knownSuffixLength = 0); QStringList m_matchingMimeTypes; // only those with highest weight QStringList m_allMatchingMimeTypes; int m_weight = 0; - int m_matchingPatternLength = 0; - int m_knownSuffixLength = 0; + qsizetype m_matchingPatternLength = 0; + qsizetype m_knownSuffixLength = 0; }; class MimeGlobPattern diff --git a/src/libs/utils/mimetypes2/mimemagicrule.cpp b/src/libs/utils/mimetypes2/mimemagicrule.cpp index ae0962a1b9d..1c19a184e6a 100644 --- a/src/libs/utils/mimetypes2/mimemagicrule.cpp +++ b/src/libs/utils/mimetypes2/mimemagicrule.cpp @@ -73,12 +73,12 @@ bool MimeMagicRule::operator==(const MimeMagicRule &other) const } // Used by both providers -bool MimeMagicRule::matchSubstring(const char *dataPtr, int dataSize, int rangeStart, int rangeLength, - int valueLength, const char *valueData, const char *mask) +bool MimeMagicRule::matchSubstring(const char *dataPtr, qsizetype dataSize, int rangeStart, int rangeLength, + qsizetype valueLength, const char *valueData, const char *mask) { // Size of searched data. // Example: value="ABC", rangeLength=3 -> we need 3+3-1=5 bytes (ABCxx,xABCx,xxABC would match) - const int dataNeeded = qMin(rangeLength + valueLength - 1, dataSize - rangeStart); + const qsizetype dataNeeded = qMin(rangeLength + valueLength - 1, dataSize - rangeStart); if (!mask) { // callgrind says QByteArray::indexOf is much slower, since our strings are typically too @@ -102,7 +102,7 @@ bool MimeMagicRule::matchSubstring(const char *dataPtr, int dataSize, int rangeS // deviceSize is 4, so dataNeeded was max'ed to 4. // maxStartPos = 4 - 3 + 1 = 2, and indeed // we need to check for a match a positions 0 and 1 (ABCx and xABC). - const int maxStartPos = dataNeeded - valueLength + 1; + const qsizetype maxStartPos = dataNeeded - valueLength + 1; for (int i = 0; i < maxStartPos; ++i) { const char *d = readDataBase + i; bool valid = true; @@ -235,7 +235,7 @@ MimeMagicRule::MimeMagicRule(const QString &type, *errorString = "Type "_L1 + type + " is not supported"_L1; // Parse for offset as "1" or "1:10" - const int colonIndex = offsets.indexOf(u':'); + const qsizetype colonIndex = offsets.indexOf(u':'); const QStringView startPosStr = QStringView(offsets).mid(0, colonIndex); // \ These decay to returning 'offsets' const QStringView endPosStr = QStringView(offsets) diff --git a/src/libs/utils/mimetypes2/mimemagicrule_p.h b/src/libs/utils/mimetypes2/mimemagicrule_p.h index 293f61ca914..ddd807b9cf7 100644 --- a/src/libs/utils/mimetypes2/mimemagicrule_p.h +++ b/src/libs/utils/mimetypes2/mimemagicrule_p.h @@ -75,7 +75,9 @@ public: static Type type(const QByteArray &type); static QByteArray typeName(Type type); - static bool matchSubstring(const char *dataPtr, int dataSize, int rangeStart, int rangeLength, int valueLength, const char *valueData, const char *mask); + static bool matchSubstring(const char *dataPtr, qsizetype dataSize, int rangeStart, + int rangeLength, qsizetype valueLength, const char *valueData, + const char *mask); private: // added for Qt Creator diff --git a/src/libs/utils/mimetypes2/mimeprovider.cpp b/src/libs/utils/mimetypes2/mimeprovider.cpp index 38fbd527855..e2ab9ffebda 100644 --- a/src/libs/utils/mimetypes2/mimeprovider.cpp +++ b/src/libs/utils/mimetypes2/mimeprovider.cpp @@ -273,7 +273,7 @@ bool MimeBinaryProvider::matchSuffixTree(MimeGlobMatchResult &result, int numEntries, int firstOffset, const QString &fileName, - int charPos, + qsizetype charPos, bool caseSensitiveCheck) { QChar fileChar = fileName[charPos]; @@ -330,7 +330,7 @@ bool MimeBinaryProvider::matchSuffixTree(MimeGlobMatchResult &result, bool MimeBinaryProvider::matchMagicRule(MimeBinaryProvider::CacheFile *cacheFile, int numMatchlets, int firstOffset, const QByteArray &data) { const char *dataPtr = data.constData(); - const int dataSize = data.size(); + const qsizetype dataSize = data.size(); for (int matchlet = 0; matchlet < numMatchlets; ++matchlet) { const int off = firstOffset + matchlet * 32; const int rangeStart = cacheFile->getUint32(off); diff --git a/src/libs/utils/mimetypes2/mimeprovider_p.h b/src/libs/utils/mimetypes2/mimeprovider_p.h index 27d809ee5ea..03d6a2c91c2 100644 --- a/src/libs/utils/mimetypes2/mimeprovider_p.h +++ b/src/libs/utils/mimetypes2/mimeprovider_p.h @@ -105,7 +105,7 @@ private: int numEntries, int firstOffset, const QString &fileName, - int charPos, + qsizetype charPos, bool caseSensitiveCheck); bool matchMagicRule(CacheFile *cacheFile, int numMatchlets, int firstOffset, const QByteArray &data); QLatin1StringView iconForMime(CacheFile *cacheFile, int posListOffset, const QByteArray &inputMime);