summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-09-15 08:04:16 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-09-16 09:27:28 (GMT)
commitccaabe9ed3f85ddfeda8993efb5c386987bac35d (patch)
tree335bf1fc5436cd130186c70fc84da2162c2f2b78 /src
parentf5c2e6374b9f6c39a2e535f7282c7d7160591ba6 (diff)
downloadQt-ccaabe9ed3f85ddfeda8993efb5c386987bac35d.zip
Qt-ccaabe9ed3f85ddfeda8993efb5c386987bac35d.tar.gz
Qt-ccaabe9ed3f85ddfeda8993efb5c386987bac35d.tar.bz2
Small optimisation in QFontMetrics multi-length-string
Change the len instead of copying the string. Idea from Warwick Reviewed-by: Warwick Allison
Diffstat (limited to 'src')
-rw-r--r--src/gui/text/qfontmetrics.cpp10
1 files 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));
}