QtGui: 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: Id83c60cc7568b20ef008b51c582cfdf466a47e35 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>bb10
parent
90988a2c67
commit
6030e63037
|
|
@ -761,7 +761,7 @@ static void set_text(const QImage &image, png_structp png_ptr, png_infop info_pt
|
|||
QMap<QString, QString>::ConstIterator it = text.constBegin();
|
||||
int i = 0;
|
||||
while (it != text.constEnd()) {
|
||||
text_ptr[i].key = qstrdup(it.key().left(79).toLatin1().constData());
|
||||
text_ptr[i].key = qstrdup(it.key().leftRef(79).toLatin1().constData());
|
||||
bool noCompress = (it.value().length() < 40);
|
||||
|
||||
#ifdef PNG_iTXt_SUPPORTED
|
||||
|
|
|
|||
|
|
@ -1154,21 +1154,22 @@ int QKeySequencePrivate::decodeString(const QString &str, QKeySequence::Sequence
|
|||
}
|
||||
|
||||
int p = accel.lastIndexOf(QLatin1Char('+'), str.length() - 2); // -2 so that Ctrl++ works
|
||||
QStringRef accelRef(&accel);
|
||||
if(p > 0)
|
||||
accel = accel.mid(p + 1);
|
||||
accelRef = accelRef.mid(p + 1);
|
||||
|
||||
int fnum = 0;
|
||||
if (accel.length() == 1) {
|
||||
if (accelRef.length() == 1) {
|
||||
#if defined(Q_OS_MACX)
|
||||
int qtKey = qtkeyForMacSymbol(accel.at(0));
|
||||
int qtKey = qtkeyForMacSymbol(accelRef.at(0));
|
||||
if (qtKey != -1) {
|
||||
ret |= qtKey;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
ret |= accel.at(0).toUpper().unicode();
|
||||
ret |= accelRef.at(0).toUpper().unicode();
|
||||
}
|
||||
} else if (accel.at(0) == QLatin1Char('f') && (fnum = accel.mid(1).toInt()) >= 1 && fnum <= 35) {
|
||||
} else if (accelRef.at(0) == QLatin1Char('f') && (fnum = accelRef.mid(1).toInt()) >= 1 && fnum <= 35) {
|
||||
ret |= Qt::Key_F1 + fnum - 1;
|
||||
} else {
|
||||
// For NativeText, check the traslation table first,
|
||||
|
|
@ -1182,7 +1183,7 @@ int QKeySequencePrivate::decodeString(const QString &str, QKeySequence::Sequence
|
|||
QString keyName(tran == 0
|
||||
? QCoreApplication::translate("QShortcut", keyname[i].name)
|
||||
: QString::fromLatin1(keyname[i].name));
|
||||
if (accel == keyName.toLower()) {
|
||||
if (accelRef == keyName.toLower()) {
|
||||
ret |= keyname[i].key;
|
||||
found = true;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -1510,7 +1510,7 @@ QRect Declaration::rectValue() const
|
|||
const QStringList func = v.variant.toStringList();
|
||||
if (func.count() != 2 || func.at(0).compare(QLatin1String("rect")) != 0)
|
||||
return QRect();
|
||||
QStringList args = func[1].split(QLatin1Char(' '), QString::SkipEmptyParts);
|
||||
const auto args = func[1].splitRef(QLatin1Char(' '), QString::SkipEmptyParts);
|
||||
if (args.count() != 4)
|
||||
return QRect();
|
||||
QRect rect(args[0].toInt(), args[1].toInt(), args[2].toInt(), args[3].toInt());
|
||||
|
|
@ -1915,9 +1915,8 @@ bool StyleSelector::basicSelectorMatches(const BasicSelector &sel, NodePtr node)
|
|||
return false;
|
||||
|
||||
if (a.valueMatchCriterium == QCss::AttributeSelector::MatchContains) {
|
||||
|
||||
QStringList lst = attrValue.split(QLatin1Char(' '));
|
||||
if (!lst.contains(a.value))
|
||||
const auto lst = attrValue.splitRef(QLatin1Char(' '));
|
||||
if (!lst.contains(QStringRef(&a.value)))
|
||||
return false;
|
||||
} else if (
|
||||
(a.valueMatchCriterium == QCss::AttributeSelector::MatchEqual
|
||||
|
|
|
|||
|
|
@ -2033,7 +2033,7 @@ uint qHash(const QFont &font, uint seed) Q_DECL_NOTHROW
|
|||
*/
|
||||
bool QFont::fromString(const QString &descrip)
|
||||
{
|
||||
QStringList l(descrip.split(QLatin1Char(',')));
|
||||
const auto l = descrip.splitRef(QLatin1Char(','));
|
||||
|
||||
int count = l.count();
|
||||
if (!count || (count > 2 && count < 9) || count > 11) {
|
||||
|
|
@ -2042,7 +2042,7 @@ bool QFont::fromString(const QString &descrip)
|
|||
return false;
|
||||
}
|
||||
|
||||
setFamily(l[0]);
|
||||
setFamily(l[0].toString());
|
||||
if (count > 1 && l[1].toDouble() > 0.0)
|
||||
setPointSizeF(l[1].toDouble());
|
||||
if (count == 9) {
|
||||
|
|
|
|||
|
|
@ -697,15 +697,15 @@ static QStringList familyList(const QFontDef &req)
|
|||
if (req.family.isEmpty())
|
||||
return family_list;
|
||||
|
||||
QStringList list = req.family.split(QLatin1Char(','));
|
||||
const auto list = req.family.splitRef(QLatin1Char(','));
|
||||
const int numFamilies = list.size();
|
||||
family_list.reserve(numFamilies);
|
||||
for (int i = 0; i < numFamilies; ++i) {
|
||||
QString str = list.at(i).trimmed();
|
||||
QStringRef str = list.at(i).trimmed();
|
||||
if ((str.startsWith(QLatin1Char('"')) && str.endsWith(QLatin1Char('"')))
|
||||
|| (str.startsWith(QLatin1Char('\'')) && str.endsWith(QLatin1Char('\''))))
|
||||
str = str.mid(1, str.length() - 2);
|
||||
family_list << str;
|
||||
family_list << str.toString();
|
||||
}
|
||||
|
||||
// append the substitute list for each family in family_list
|
||||
|
|
|
|||
Loading…
Reference in New Issue