Minor optimizations for QTextEngine

Optimize script assignment, skip calls to QUnicodeTables::script() for
the codepoints handled explicitly.
Make the helper functions of QTextEngine::elidedText() inlined

Merge-request: 1298
Reviewed-by: yoann
(cherry picked from commit 857202824e7d6083eeb87fc52d3770f8fd82b559)

Change-Id: I1afc6405a800dbc2b5f63a2f98c63e607e3ee255
Reviewed-on: http://codereview.qt.nokia.com/2998
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
This commit is contained in:
Ritt Konstantin 2011-07-13 04:41:45 +04:00 committed by Qt by Nokia
parent 3cea6b22a6
commit 4b6fe1bdc8

View File

@ -1532,33 +1532,40 @@ void QTextEngine::itemize() const
const ushort *e = uc + length; const ushort *e = uc + length;
int lastScript = QUnicodeTables::Common; int lastScript = QUnicodeTables::Common;
while (uc < e) { while (uc < e) {
int script = QUnicodeTables::script(*uc); switch (*uc) {
if (script == QUnicodeTables::Inherited) case QChar::ObjectReplacementCharacter:
script = lastScript;
analysis->flags = QScriptAnalysis::None;
if (*uc == QChar::ObjectReplacementCharacter) {
if (analysis->bidiLevel % 2) if (analysis->bidiLevel % 2)
--analysis->bidiLevel; --analysis->bidiLevel;
analysis->script = QUnicodeTables::Common; analysis->script = QUnicodeTables::Common;
analysis->flags = QScriptAnalysis::Object; analysis->flags = QScriptAnalysis::Object;
} else if (*uc == QChar::LineSeparator) { break;
case QChar::LineSeparator:
if (analysis->bidiLevel % 2) if (analysis->bidiLevel % 2)
--analysis->bidiLevel; --analysis->bidiLevel;
analysis->script = QUnicodeTables::Common; analysis->script = QUnicodeTables::Common;
analysis->flags = QScriptAnalysis::LineOrParagraphSeparator; analysis->flags = QScriptAnalysis::LineOrParagraphSeparator;
if (option.flags() & QTextOption::ShowLineAndParagraphSeparators) if (option.flags() & QTextOption::ShowLineAndParagraphSeparators)
*const_cast<ushort*>(uc) = 0x21B5; // visual line separator *const_cast<ushort*>(uc) = 0x21B5; // visual line separator
} else if (*uc == 9) { break;
case 9: // Tab
analysis->script = QUnicodeTables::Common; analysis->script = QUnicodeTables::Common;
analysis->flags = QScriptAnalysis::Tab; analysis->flags = QScriptAnalysis::Tab;
analysis->bidiLevel = control.baseLevel(); analysis->bidiLevel = control.baseLevel();
} else if ((*uc == 32 || *uc == QChar::Nbsp) break;
&& (option.flags() & QTextOption::ShowTabsAndSpaces)) { case 32: // Space
analysis->script = QUnicodeTables::Common; case QChar::Nbsp:
analysis->flags = QScriptAnalysis::Space; if (option.flags() & QTextOption::ShowTabsAndSpaces) {
analysis->bidiLevel = control.baseLevel(); analysis->script = QUnicodeTables::Common;
} else { analysis->flags = QScriptAnalysis::Space;
analysis->script = script; analysis->bidiLevel = control.baseLevel();
break;
}
// fall through
default:
int script = QUnicodeTables::script(*uc);
analysis->script = script == QUnicodeTables::Inherited ? lastScript : script;
analysis->flags = QScriptAnalysis::None;
break;
} }
lastScript = analysis->script; lastScript = analysis->script;
++uc; ++uc;
@ -2432,7 +2439,7 @@ void QTextEngine::indexAdditionalFormats()
between the text that gets truncated and the ellipsis. This is important to get between the text that gets truncated and the ellipsis. This is important to get
correctly shaped results for arabic text. correctly shaped results for arabic text.
*/ */
static bool nextCharJoins(const QString &string, int pos) static inline bool nextCharJoins(const QString &string, int pos)
{ {
while (pos < string.length() && string.at(pos).category() == QChar::Mark_NonSpacing) while (pos < string.length() && string.at(pos).category() == QChar::Mark_NonSpacing)
++pos; ++pos;
@ -2441,13 +2448,14 @@ static bool nextCharJoins(const QString &string, int pos)
return string.at(pos).joining() != QChar::OtherJoining; return string.at(pos).joining() != QChar::OtherJoining;
} }
static bool prevCharJoins(const QString &string, int pos) static inline bool prevCharJoins(const QString &string, int pos)
{ {
while (pos > 0 && string.at(pos - 1).category() == QChar::Mark_NonSpacing) while (pos > 0 && string.at(pos - 1).category() == QChar::Mark_NonSpacing)
--pos; --pos;
if (pos == 0) if (pos == 0)
return false; return false;
return (string.at(pos - 1).joining() == QChar::Dual || string.at(pos - 1).joining() == QChar::Center); QChar::Joining joining = string.at(pos - 1).joining();
return (joining == QChar::Dual || joining == QChar::Center);
} }
QString QTextEngine::elidedText(Qt::TextElideMode mode, const QFixed &width, int flags) const QString QTextEngine::elidedText(Qt::TextElideMode mode, const QFixed &width, int flags) const