more performance optimizations + cleanup

This commit is contained in:
Agel committed 2026-10-29 12:12:02 +01:00
1 parent b23713bea6
commit d9a0991f9b
15 files changed
+396 -469

No files matched your search

+16 -12
View File
@@ -41,13 +41,13 @@ public:
QByteArray contentHash() const override { return QByteArray("texthash"); }
bool loadMetadata(const QString &) override { return true; }
QStringList chunks() const override
QVector<ContentChunk> chunks() const override
{
return {
QStringLiteral("<p>Chunk 1</p>"),
QStringLiteral("<p>Chunk 2</p>"),
QStringLiteral("<p>Chunk 3</p>")
};
return HtmlBlockParser::parseChunks(
QStringLiteral("<p>Chunk 1</p><p>Chunk 2</p><p>Chunk 3</p>"),
QStringLiteral("text/ch1.xhtml"),
1 // targetChars = 1 forces each paragraph into its own chunk
);
}
};
@@ -63,12 +63,16 @@ public:
QByteArray contentHash() const override { return QByteArray("manychunks"); }
bool loadMetadata(const QString &) override { return true; }
QStringList chunks() const override
QVector<ContentChunk> chunks() const override
{
QStringList list;
QVector<ContentChunk> list;
list.reserve(60);
for (int i = 0; i < 60; ++i) {
list.append(QStringLiteral("<p>Paragraph chunk number %1 with some text content.</p>").arg(i));
auto parsed = HtmlBlockParser::parseChunks(
QStringLiteral("<p>Paragraph chunk number %1 with some text content.</p>").arg(i),
QStringLiteral("text/ch1.xhtml")
);
list.append(parsed);
}
return list;
}
@@ -200,11 +204,11 @@ private slots:
QVERIFY(model.isTextMode());
QCOMPARE(model.rowCount(), 3);
QCOMPARE(model.data(model.index(0, 0), ReadingModel::ContentRole).toString(),
QStringLiteral("<p>Chunk 1</p>"));
QStringLiteral("text/ch1.xhtml"));
QCOMPARE(model.data(model.index(1, 0), ReadingModel::ContentRole).toString(),
QStringLiteral("<p>Chunk 2</p>"));
QStringLiteral("text/ch1.xhtml"));
QCOMPARE(model.data(model.index(2, 0), ReadingModel::ContentRole).toString(),
QStringLiteral("<p>Chunk 3</p>"));
QStringLiteral("text/ch1.xhtml"));
QTRY_COMPARE(restoreSpy.count(), 1);