From 9b699fa839f560a9ea9da69c8975b9aa4654ab8b Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Tue, 5 Apr 2016 18:39:14 +0300 Subject: Widgets: use QStringRef to optimize memory allocation Replace substring functions that return QString with corresponding functions that return QStringRef where it's possible. Create QString from QStringRef only where necessary. Change-Id: Id1c39093199519f2794b11560c2c0ded2d52b928 Reviewed-by: Marc Mutz --- src/widgets/styles/qfusionstyle.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/widgets/styles/qfusionstyle.cpp') diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index b15b9701d9..5b6e47e2c6 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -1649,7 +1649,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin); QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect); - QString s = menuitem->text; + QStringRef s(&menuitem->text); if (!s.isEmpty()) { // draw text p->save(); int t = s.indexOf(QLatin1Char('\t')); @@ -1660,12 +1660,13 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio if (t >= 0) { QRect vShortcutRect = visualRect(opt->direction, menuitem->rect, QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom()))); + const QString textToDraw = s.mid(t + 1).toString(); if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, option, widget)) { p->setPen(menuitem->palette.light().color()); - p->drawText(vShortcutRect.adjusted(1, 1, 1, 1), text_flags, s.mid(t + 1)); + p->drawText(vShortcutRect.adjusted(1, 1, 1, 1), text_flags, textToDraw); p->setPen(discol); } - p->drawText(vShortcutRect, text_flags, s.mid(t + 1)); + p->drawText(vShortcutRect, text_flags, textToDraw); s = s.left(t); } QFont font = menuitem->font; @@ -1680,12 +1681,13 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio font.setBold(true); p->setFont(font); + const QString textToDraw = s.left(t).toString(); if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, option, widget)) { p->setPen(menuitem->palette.light().color()); - p->drawText(vTextRect.adjusted(1, 1, 1, 1), text_flags, s.left(t)); + p->drawText(vTextRect.adjusted(1, 1, 1, 1), text_flags, textToDraw); p->setPen(discol); } - p->drawText(vTextRect, text_flags, s.left(t)); + p->drawText(vTextRect, text_flags, textToDraw); p->restore(); } -- cgit v1.2.3