QmlJS: Avoid deprecation warning

de18b3ff370543b5b99bd068b871a2cd677cf9f3 deprecated the
QCryptographicHash::addData(const char *data, qsizetype length)
overload.

Change-Id: I86444a9d7de3cafc596f508fc08c3a4c1f25142f
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2023-06-06 09:00:27 +02:00
parent 82966bc7ba
commit cfa88ac169

View File

@@ -369,61 +369,62 @@ LibraryInfo::LibraryInfo(const QmlDirParser &parser, const QByteArray &fingerpri
QByteArray LibraryInfo::calculateFingerprint() const QByteArray LibraryInfo::calculateFingerprint() const
{ {
QCryptographicHash hash(QCryptographicHash::Sha1); QCryptographicHash hash(QCryptographicHash::Sha1);
hash.addData(reinterpret_cast<const char *>(&_status), sizeof(_status)); auto addData = [&hash](auto p, size_t len) {
hash.addData(QByteArrayView(reinterpret_cast<const char *>(p), len));
};
addData(&_status, sizeof(_status));
int len = _components.size(); int len = _components.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(&len, sizeof(len));
for (const QmlDirParser::Component &component : _components) { for (const QmlDirParser::Component &component : _components) {
len = component.fileName.size(); len = component.fileName.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(&len, sizeof(len));
hash.addData(reinterpret_cast<const char *>(component.fileName.constData()), addData(component.fileName.constData(), len * sizeofQChar);
len * sizeofQChar); addData(&component.majorVersion, sizeof(component.majorVersion));
hash.addData(reinterpret_cast<const char *>(&component.majorVersion), sizeof(component.majorVersion)); addData(&component.minorVersion, sizeof(component.minorVersion));
hash.addData(reinterpret_cast<const char *>(&component.minorVersion), sizeof(component.minorVersion));
len = component.typeName.size(); len = component.typeName.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(&len, sizeof(len));
hash.addData(reinterpret_cast<const char *>(component.typeName.constData()), addData(component.typeName.constData(), component.typeName.size() * sizeofQChar);
component.typeName.size() * sizeofQChar);
int flags = (component.singleton ? (1 << 0) : 0) + (component.internal ? (1 << 1) : 0); int flags = (component.singleton ? (1 << 0) : 0) + (component.internal ? (1 << 1) : 0);
hash.addData(reinterpret_cast<const char *>(&flags), sizeof(flags)); addData(&flags, sizeof(flags));
} }
len = _plugins.size(); len = _plugins.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(&len, sizeof(len));
for (const QmlDirParser::Plugin &plugin : _plugins) { for (const QmlDirParser::Plugin &plugin : _plugins) {
len = plugin.path.size(); len = plugin.path.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(&len, sizeof(len));
hash.addData(reinterpret_cast<const char *>(plugin.path.constData()), len * sizeofQChar); addData(plugin.path.constData(), len * sizeofQChar);
len = plugin.name.size(); len = plugin.name.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(&len, sizeof(len));
hash.addData(reinterpret_cast<const char *>(plugin.name.constData()), len * sizeofQChar); addData(plugin.name.constData(), len * sizeofQChar);
} }
len = _typeinfos.size(); len = _typeinfos.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(&len, sizeof(len));
for (const QString &typeinfo : _typeinfos) { for (const QString &typeinfo : _typeinfos) {
len = typeinfo.size(); len = typeinfo.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(&len, sizeof(len));
hash.addData(reinterpret_cast<const char *>(typeinfo.constData()), addData(typeinfo.constData(), len * sizeofQChar);
len * sizeofQChar);
} }
len = _metaObjects.size(); len = _metaObjects.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(&len, sizeof(len));
QList<QByteArray> metaFingerprints; QList<QByteArray> metaFingerprints;
for (const LanguageUtils::FakeMetaObject::ConstPtr &metaObject : _metaObjects) for (const LanguageUtils::FakeMetaObject::ConstPtr &metaObject : _metaObjects)
metaFingerprints.append(metaObject->fingerprint()); metaFingerprints.append(metaObject->fingerprint());
std::sort(metaFingerprints.begin(), metaFingerprints.end()); std::sort(metaFingerprints.begin(), metaFingerprints.end());
for (const QByteArray &fp : std::as_const(metaFingerprints)) for (const QByteArray &fp : std::as_const(metaFingerprints))
hash.addData(fp); hash.addData(fp);
hash.addData(reinterpret_cast<const char *>(&_dumpStatus), sizeof(_dumpStatus)); addData(&_dumpStatus, sizeof(_dumpStatus));
len = _dumpError.size(); // localization dependent (avoid?) len = _dumpError.size(); // localization dependent (avoid?)
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(&len, sizeof(len));
hash.addData(reinterpret_cast<const char *>(_dumpError.constData()), len * sizeofQChar); addData(_dumpError.constData(), len * sizeofQChar);
len = _moduleApis.size(); len = _moduleApis.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(&len, sizeof(len));
for (const ModuleApiInfo &moduleInfo : _moduleApis) for (const ModuleApiInfo &moduleInfo : _moduleApis)
moduleInfo.addToHash(hash); // make it order independent? moduleInfo.addToHash(hash); // make it order independent?
len = _imports.size(); len = _imports.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); addData(&len, sizeof(len));
for (const QmlDirParser::Import &import : _imports) for (const QmlDirParser::Import &import : _imports)
hash.addData(import.module.toUtf8()); // import order matters, keep order-dependent hash.addData(import.module.toUtf8()); // import order matters, keep order-dependent