From b21403992edc687fd6b2f24b2026172c52453dbf Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Sun, 29 Aug 2021 22:33:53 +0500 Subject: [PATCH] QTextDocumentLayout: remove multiple calls to lineHeightType Get LineHeightType once and reuse the value. There still are 2 calls to lineHeightType from inside the QTextBlockFormat::lineHeight but leaving them cause they need a bigger change. Change-Id: I4016a5e483a0358d43f73d174a74545d4f3be338 Reviewed-by: Konstantin Ritt Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qtextdocumentlayout.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp index f8b4474e097..c5ef47e682f 100644 --- a/src/gui/text/qtextdocumentlayout.cpp +++ b/src/gui/text/qtextdocumentlayout.cpp @@ -3415,19 +3415,21 @@ void QTextDocumentLayoutPrivate::layoutFlow(QTextFrame::Iterator it, QTextLayout static inline void getLineHeightParams(const QTextBlockFormat &blockFormat, const QTextLine &line, qreal scaling, QFixed *lineAdjustment, QFixed *lineBreakHeight, QFixed *lineHeight, QFixed *lineBottom) { + const qreal height = line.height(); + const int lineHeightType = blockFormat.lineHeightType(); qreal rawHeight = qCeil(line.ascent() + line.descent() + line.leading()); *lineHeight = QFixed::fromReal(blockFormat.lineHeight(rawHeight, scaling)); - *lineBottom = QFixed::fromReal(blockFormat.lineHeight(line.height(), scaling)); + *lineBottom = QFixed::fromReal(blockFormat.lineHeight(height, scaling)); - if (blockFormat.lineHeightType() == QTextBlockFormat::FixedHeight || blockFormat.lineHeightType() == QTextBlockFormat::MinimumHeight) { + if (lineHeightType == QTextBlockFormat::FixedHeight || lineHeightType == QTextBlockFormat::MinimumHeight) { *lineBreakHeight = *lineBottom; - if (blockFormat.lineHeightType() == QTextBlockFormat::FixedHeight) + if (lineHeightType == QTextBlockFormat::FixedHeight) *lineAdjustment = QFixed::fromReal(line.ascent() + qMax(line.leading(), qreal(0.0))) - ((*lineHeight * 4) / 5); else - *lineAdjustment = QFixed::fromReal(line.height()) - *lineHeight; + *lineAdjustment = QFixed::fromReal(height) - *lineHeight; } else { - *lineBreakHeight = QFixed::fromReal(line.height()); + *lineBreakHeight = QFixed::fromReal(height); *lineAdjustment = 0; } }