Update mime database from Qt

qtbase/c1e1d133c47f6cbeee045dcec0dfe7c68d5bef34
  mimetypes/: port to qsizetype

Change-Id: I4ec76cc3af25efdadd31cb6d58235f0a55bf321a
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
Eike Ziller
2024-08-27 14:11:39 +02:00
parent 9c21c0a2a1
commit 0be60cad2f
7 changed files with 26 additions and 26 deletions

View File

@@ -735,7 +735,7 @@ QList<MimeType> MimeDatabase::mimeTypesForFileName(const QString &fileName) cons
QString MimeDatabase::suffixForFileName(const QString &fileName) const QString MimeDatabase::suffixForFileName(const QString &fileName) const
{ {
QMutexLocker locker(&d->mutex); QMutexLocker locker(&d->mutex);
const int suffixLength = d->findByFileName(fileName).m_knownSuffixLength; const qsizetype suffixLength = d->findByFileName(fileName).m_knownSuffixLength;
return fileName.right(suffixLength); return fileName.right(suffixLength);
} }

View File

@@ -22,7 +22,8 @@ namespace Utils {
Handles glob weights, and preferring longer matches over shorter matches. 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)) if (m_allMatchingMimeTypes.contains(mimeType))
return; return;
@@ -59,11 +60,11 @@ void MimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const QS
MimeGlobPattern::PatternType MimeGlobPattern::detectPatternType(const QString &pattern) const MimeGlobPattern::PatternType MimeGlobPattern::detectPatternType(const QString &pattern) const
{ {
const int patternLength = pattern.size(); const qsizetype patternLength = pattern.size();
if (!patternLength) if (!patternLength)
return OtherPattern; return OtherPattern;
const int starCount = pattern.count(u'*'); const qsizetype starCount = pattern.count(u'*');
const bool hasSquareBracket = pattern.indexOf(u'[') != -1; const bool hasSquareBracket = pattern.indexOf(u'[') != -1;
const bool hasQuestionMark = 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 const QString fileName = m_caseSensitivity == Qt::CaseInsensitive
? inputFileName.toLower() : inputFileName; ? inputFileName.toLower() : inputFileName;
const int patternLength = m_pattern.size(); const qsizetype patternLength = m_pattern.size();
if (!patternLength) if (!patternLength)
return false; return false;
const int fileNameLength = fileName.size(); const qsizetype fileNameLength = fileName.size();
switch (m_patternType) { switch (m_patternType) {
case SuffixPattern: { case SuffixPattern: {
@@ -224,16 +225,12 @@ void MimeGlobPatternList::match(MimeGlobMatchResult &result,
const QString &fileName, const QString &fileName,
const QSet<QString> &ignoreMimeTypes) const const QSet<QString> &ignoreMimeTypes) const
{ {
for (const MimeGlobPattern &glob : *this) {
MimeGlobPatternList::const_iterator it = this->constBegin();
const MimeGlobPatternList::const_iterator endIt = this->constEnd();
for (; it != endIt; ++it) {
const MimeGlobPattern &glob = *it;
if (ignoreMimeTypes.contains(glob.mimeType())) if (ignoreMimeTypes.contains(glob.mimeType()))
continue; continue;
if (glob.matchFileName(fileName)) { if (glob.matchFileName(fileName)) {
const QString pattern = glob.pattern(); 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); 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 // 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) // (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 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(); const QString simpleExtension = fileName.right(ext_len).toLower();
// (toLower because fast patterns are always case-insensitive and saved as lowercase) // (toLower because fast patterns are always case-insensitive and saved as lowercase)

View File

@@ -21,13 +21,14 @@ namespace Utils {
struct MimeGlobMatchResult 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_matchingMimeTypes; // only those with highest weight
QStringList m_allMatchingMimeTypes; QStringList m_allMatchingMimeTypes;
int m_weight = 0; int m_weight = 0;
int m_matchingPatternLength = 0; qsizetype m_matchingPatternLength = 0;
int m_knownSuffixLength = 0; qsizetype m_knownSuffixLength = 0;
}; };
class MimeGlobPattern class MimeGlobPattern

View File

@@ -73,12 +73,12 @@ bool MimeMagicRule::operator==(const MimeMagicRule &other) const
} }
// Used by both providers // Used by both providers
bool MimeMagicRule::matchSubstring(const char *dataPtr, int dataSize, int rangeStart, int rangeLength, bool MimeMagicRule::matchSubstring(const char *dataPtr, qsizetype dataSize, int rangeStart, int rangeLength,
int valueLength, const char *valueData, const char *mask) qsizetype valueLength, const char *valueData, const char *mask)
{ {
// Size of searched data. // Size of searched data.
// Example: value="ABC", rangeLength=3 -> we need 3+3-1=5 bytes (ABCxx,xABCx,xxABC would match) // 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) { if (!mask) {
// callgrind says QByteArray::indexOf is much slower, since our strings are typically too // 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. // deviceSize is 4, so dataNeeded was max'ed to 4.
// maxStartPos = 4 - 3 + 1 = 2, and indeed // maxStartPos = 4 - 3 + 1 = 2, and indeed
// we need to check for a match a positions 0 and 1 (ABCx and xABC). // 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) { for (int i = 0; i < maxStartPos; ++i) {
const char *d = readDataBase + i; const char *d = readDataBase + i;
bool valid = true; bool valid = true;
@@ -235,7 +235,7 @@ MimeMagicRule::MimeMagicRule(const QString &type,
*errorString = "Type "_L1 + type + " is not supported"_L1; *errorString = "Type "_L1 + type + " is not supported"_L1;
// Parse for offset as "1" or "1:10" // Parse for offset as "1" or "1:10"
const int colonIndex = offsets.indexOf(u':'); const qsizetype colonIndex = offsets.indexOf(u':');
const QStringView startPosStr const QStringView startPosStr
= QStringView(offsets).mid(0, colonIndex); // \ These decay to returning 'offsets' = QStringView(offsets).mid(0, colonIndex); // \ These decay to returning 'offsets'
const QStringView endPosStr = QStringView(offsets) const QStringView endPosStr = QStringView(offsets)

View File

@@ -75,7 +75,9 @@ public:
static Type type(const QByteArray &type); static Type type(const QByteArray &type);
static QByteArray typeName(Type 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: private:
// added for Qt Creator // added for Qt Creator

View File

@@ -273,7 +273,7 @@ bool MimeBinaryProvider::matchSuffixTree(MimeGlobMatchResult &result,
int numEntries, int numEntries,
int firstOffset, int firstOffset,
const QString &fileName, const QString &fileName,
int charPos, qsizetype charPos,
bool caseSensitiveCheck) bool caseSensitiveCheck)
{ {
QChar fileChar = fileName[charPos]; 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) bool MimeBinaryProvider::matchMagicRule(MimeBinaryProvider::CacheFile *cacheFile, int numMatchlets, int firstOffset, const QByteArray &data)
{ {
const char *dataPtr = data.constData(); const char *dataPtr = data.constData();
const int dataSize = data.size(); const qsizetype dataSize = data.size();
for (int matchlet = 0; matchlet < numMatchlets; ++matchlet) { for (int matchlet = 0; matchlet < numMatchlets; ++matchlet) {
const int off = firstOffset + matchlet * 32; const int off = firstOffset + matchlet * 32;
const int rangeStart = cacheFile->getUint32(off); const int rangeStart = cacheFile->getUint32(off);

View File

@@ -105,7 +105,7 @@ private:
int numEntries, int numEntries,
int firstOffset, int firstOffset,
const QString &fileName, const QString &fileName,
int charPos, qsizetype charPos,
bool caseSensitiveCheck); bool caseSensitiveCheck);
bool matchMagicRule(CacheFile *cacheFile, int numMatchlets, int firstOffset, const QByteArray &data); bool matchMagicRule(CacheFile *cacheFile, int numMatchlets, int firstOffset, const QByteArray &data);
QLatin1StringView iconForMime(CacheFile *cacheFile, int posListOffset, const QByteArray &inputMime); QLatin1StringView iconForMime(CacheFile *cacheFile, int posListOffset, const QByteArray &inputMime);