summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2023-11-13 19:53:18 -0800
committerThiago Macieira <thiago.macieira@intel.com>2023-11-28 03:14:03 -0800
commitb2d24044c2b001851b5aa88d92a0d5de57f25210 (patch)
tree2fc32b8965d9acf6bc5a5687746ed13e47aae0f2
parent878e3342e1c9bd8a4da6a2e9e1508dacbe0c7ab6 (diff)
QFactoryLoader: use the new UTF-8 QCborStreamReader API for performance
That way we don't need to decode to QString in order to compare to "Keys". There's no avoiding the conversion to it when inserting in the map for top-level elements, but use of moc's -M option is extremely rare. Ideally, we'd simply ask QCborStreamReader to perform a comparison to a string of ours, so we didn't have to memcpy from the stream in the first place. But TinyCBOR has no API for that (it's been pending as https://github.com/intel/tinycbor/issues/223 for a while). Change-Id: I8bd6bb457b9c42218247fffd1797607f75b153f4 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
-rw-r--r--src/corelib/plugin/qfactoryloader.cpp29
1 files changed, 7 insertions, 22 deletions
diff --git a/src/corelib/plugin/qfactoryloader.cpp b/src/corelib/plugin/qfactoryloader.cpp
index 55d5bd4f9c..b1fe671fb4 100644
--- a/src/corelib/plugin/qfactoryloader.cpp
+++ b/src/corelib/plugin/qfactoryloader.cpp
@@ -65,21 +65,6 @@ struct QFactoryLoaderIidSearch
QFactoryLoaderIidSearch(QLatin1StringView iid) : iid(iid)
{ Q_ASSERT(!iid.isEmpty()); }
- static QString readString(QCborStreamReader &reader)
- {
- QString result;
- if (!reader.isLengthKnown())
- return result;
- auto r = reader.readString();
- if (r.status != QCborStreamReader::Ok)
- return result;
- result = std::move(r.data);
- r = reader.readString();
- if (r.status != QCborStreamReader::EndOfString)
- result = QString();
- return result;
- }
-
static IterationResult::Result skip(QCborStreamReader &reader)
{
// skip this, whatever it is
@@ -91,10 +76,10 @@ struct QFactoryLoaderIidSearch
{
if (key != QtPluginMetaDataKeys::IID)
return skip(reader);
- matchesIid = (readString(reader) == iid);
+ matchesIid = (reader.toString() == iid);
return IterationResult::FinishedSearch;
}
- IterationResult::Result operator()(const QString &, QCborStreamReader &reader)
+ IterationResult::Result operator()(QUtf8StringView, QCborStreamReader &reader)
{
return skip(reader);
}
@@ -124,8 +109,8 @@ struct QFactoryLoaderMetaDataKeysExtractor : QFactoryLoaderIidSearch
return IterationResult::ParsingError;
while (reader.isValid()) {
// the metadata is JSON, so keys are all strings
- QString key = reader.toString();
- if (key == "Keys"_L1) {
+ QByteArray key = reader.toUtf8String();
+ if (key == "Keys") {
if (!reader.isArray() || !reader.isLengthKnown())
return IterationResult::InvalidHeaderItem;
keys = QCborValue::fromCbor(reader).toArray();
@@ -170,10 +155,10 @@ template <typename F> static IterationResult iterateInPluginMetaData(QByteArrayV
return reader.lastError();
r = f(key, reader);
} else if (reader.isString()) {
- QString key = readString(reader);
+ QByteArray key = reader.toUtf8String();
if (key.isNull())
return reader.lastError();
- r = f(key, reader);
+ r = f(QUtf8StringView(key), reader);
} else {
return IterationResult::InvalidTopLevelItem;
}
@@ -206,7 +191,7 @@ bool QPluginParsedMetaData::parse(QByteArrayView raw)
if constexpr (std::is_enum_v<std::decay_t<decltype(key)>>)
map[int(key)] = item;
else
- map[key] = item;
+ map[QString::fromUtf8(key)] = item;
return IterationResult::ContinueSearch;
});