From ccaabe9ed3f85ddfeda8993efb5c386987bac35d Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 15 Sep 2009 10:04:16 +0200 Subject: Small optimisation in QFontMetrics multi-length-string Change the len instead of copying the string. Idea from Warwick Reviewed-by: Warwick Allison --- src/gui/text/qfontmetrics.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/gui/text/qfontmetrics.cpp b/src/gui/text/qfontmetrics.cpp index b2784d6..ce122aa 100644 --- a/src/gui/text/qfontmetrics.cpp +++ b/src/gui/text/qfontmetrics.cpp @@ -528,13 +528,15 @@ int QFontMetrics::rightBearing(QChar ch) const int QFontMetrics::width(const QString &text, int len) const { int pos = text.indexOf(QLatin1Char('\x9c')); - QString txt = (pos == -1) ? text : text.left(pos); - if (len < 0) - len = txt.length(); + if (pos != -1) { + len = (len < 0) ? pos : qMin(pos, len); + } else if (len < 0) { + len = text.length(); + } if (len == 0) return 0; - QTextEngine layout(txt, d); + QTextEngine layout(text, d); layout.ignoreBidi = true; return qRound(layout.width(0, len)); } -- cgit v0.12