From 0102f34f1ebe91aaff6fb2edc83a7ebf7ffb4d1e Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Mon, 3 Sep 2012 18:06:17 +0200 Subject: Optimize QTextLayout/QTextEngine usage outside of QTextDocument. When QTextLayout is used in a QTextDocument, many code paths use special caches and thus greatly outperform the raw QTextLayout version that operates directly on a QString. This patch brings some of these optimizations also to the raw version. We now also use a QFormatCollection in such cases and enable the functionality of QTextEngine::indexAdditionalFormats() and QTextEngine::resolveAdditionalFormats(). Thanks to that, we can greatly speed up QTextEngine::format(), which now uses an amort O(1) hash table lookup instead of a O(N) linear search. The added benchmark shows a gain in the order of one magnitude: ./tst_bench_QText formattedLayout:long-many before applying the patch: 378.19 msecs per iteration (total: 37,820, iterations: 100) after applying the patch: 25.80 msecs per iteration (total: 2,580, iterations: 100) Note: This change is source-incompatible for applications using the private QTextEngine API. Task-number: QTBUG-8389 Change-Id: Ifcf7a8902a394428979ea06a6d955f886ee739c7 Reviewed-by: Konstantin Ritt Reviewed-by: Olivier Goffart Reviewed-by: Lars Knoll --- src/gui/text/qtextengine_p.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/gui/text/qtextengine_p.h') diff --git a/src/gui/text/qtextengine_p.h b/src/gui/text/qtextengine_p.h index d8ab222475..c2362e6dc5 100644 --- a/src/gui/text/qtextengine_p.h +++ b/src/gui/text/qtextengine_p.h @@ -541,7 +541,12 @@ public: #ifdef QT_BUILD_COMPAT_LIB return 0; // Compat should never reference this symbol #else - return block.docHandle()->formatCollection(); + if (block.docHandle()) + return block.docHandle()->formatCollection(); + else if (specialData) + return specialData->formats.data(); + + return 0; #endif } QTextCharFormat format(const QScriptItem *si) const; @@ -619,6 +624,8 @@ public: QList addFormats; QVector addFormatIndices; QVector resolvedFormatIndices; + // only used when no docHandle is available + QScopedPointer formats; }; SpecialData *specialData; -- cgit v1.2.3