QrcParser: Replace QSharedPointer with std::shared_ptr

According to https://wiki.qt.io/Things_To_Look_Out_For_In_Reviews
QSharedPointer impl is poor and it's going to be removed from Qt 7.

Change-Id: I557804bf781b7fa58129242bd94e1566ed3ee304
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2024-02-01 11:25:52 +01:00
parent 62aa35ee39
commit 5cf639341e
6 changed files with 17 additions and 22 deletions

View File

@@ -27,12 +27,12 @@
#include <QDirIterator>
#include <QFile>
#include <QFileInfo>
#include <QLibraryInfo>
#include <QMetaObject>
#include <QTextDocument>
#include <QTextStream>
#include <QTimer>
#include <QtAlgorithms>
#include <QLibraryInfo>
#include <QTimer>
using namespace Utils;
@@ -508,7 +508,7 @@ void ModelManagerInterface::iterateQrcFiles(
for (const Utils::FilePath &qrcFilePath : std::as_const(allQrcs)) {
QrcParser::ConstPtr qrcFile = m_qrcCache.parsedPath(qrcFilePath.toFSPathString());
if (qrcFile.isNull())
if (!qrcFile)
continue;
callback(qrcFile);
}

View File

@@ -5,7 +5,6 @@
#include "algorithm.h"
#include "fileutils.h"
#include "hostosinfo.h"
#include "qrcparser.h"
#include "qtcassert.h"

View File

@@ -8,7 +8,6 @@
#include "filepath.h"
#include <QHash>
#include <QSharedPointer>
#include <QStringList>
#include <QUrl>
@@ -60,7 +59,7 @@ private:
private:
FilePaths m_allQrcFiles;
mutable QHash<QUrl, FilePaths> m_fileCache;
mutable QHash<FilePath, QSharedPointer<QrcParser>> m_parserCache;
mutable QHash<FilePath, std::shared_ptr<QrcParser>> m_parserCache;
};
CacheEntry findInSearchPaths(const FilePath &filePath, FileHandler fileHandler,

View File

@@ -8,7 +8,6 @@
#include <qmljs/qmljstr.h> // Yes, the translations are still there
#include <QCoreApplication>
#include <QDir>
#include <QDomDocument>
#include <QFile>
@@ -611,8 +610,8 @@ QrcParser::Ptr QrcCachePrivate::addPath(const QString &path, const QString &cont
qCWarning(qrcParserLog) << "adding invalid qrc " << path << " to the cache:" << newParser->errorMessages();
{
QWriteLocker l(&m_mutex);
QPair<QrcParser::Ptr,int> currentValue = m_cache.value(path, {QrcParser::Ptr(nullptr), 0});
if (currentValue.first.isNull())
QPair<QrcParser::Ptr, int> currentValue = m_cache.value(path, {{}, 0});
if (!currentValue.first)
currentValue.first = newParser;
currentValue.second += 1;
m_cache.insert(path, currentValue);

View File

@@ -7,8 +7,6 @@
#include "filepath.h"
#include <QSharedPointer>
#include <QString>
#include <QStringList>
QT_BEGIN_NAMESPACE
@@ -34,8 +32,8 @@ public:
QList<Utils::FilePath> sourceFiles;
};
typedef QSharedPointer<QrcParser> Ptr;
typedef QSharedPointer<const QrcParser> ConstPtr;
using Ptr = std::shared_ptr<QrcParser>;
using ConstPtr = std::shared_ptr<const QrcParser>;
~QrcParser();
bool parseFile(const QString &path, const QString &contents);
QString firstFileAtPath(const QString &path, const QLocale &locale) const;

View File

@@ -119,25 +119,25 @@ void tst_QrcParser::firstInTest()
void tst_QrcParser::cacheTest()
{
QFETCH(QString, path);
QVERIFY(m_cache.parsedPath(path).isNull());
QVERIFY(!m_cache.parsedPath(path));
QrcParser::ConstPtr p0 = m_cache.addPath(path, QString());
QVERIFY(!p0.isNull());
QVERIFY(p0);
QrcParser::ConstPtr p1 = m_cache.parsedPath(path);
QVERIFY(p1.data() == p0.data());
QVERIFY(p1.get() == p0.get());
QrcParser::ConstPtr p2 = m_cache.addPath(path, QString());
QVERIFY(p2.data() == p1.data());
QVERIFY(p2.get() == p1.get());
QrcParser::ConstPtr p3 = m_cache.parsedPath(path);
QVERIFY(p3.data() == p2.data());
QVERIFY(p3.get() == p2.get());
QrcParser::ConstPtr p4 = m_cache.updatePath(path, QString());
QVERIFY(p4.data() != p3.data());
QVERIFY(p4.get() != p3.get());
QrcParser::ConstPtr p5 = m_cache.parsedPath(path);
QVERIFY(p5.data() == p4.data());
QVERIFY(p5.get() == p4.get());
m_cache.removePath(path);
QrcParser::ConstPtr p6 = m_cache.parsedPath(path);
QVERIFY(p6.data() == p5.data());
QVERIFY(p6.get() == p5.get());
m_cache.removePath(path);
QrcParser::ConstPtr p7 = m_cache.parsedPath(path);
QVERIFY(p7.isNull());
QVERIFY(!p7);
}
void tst_QrcParser::simpleTest()