From 1be53f4e143d417d60cd1f9a292193dab59b5b20 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Wed, 6 Apr 2016 15:23:58 +0300 Subject: 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. While touching the code, also port loops to C++11 style. Change-Id: I04c99b24ea6afd3715e3edf9ea00bfab838fd53c Reviewed-by: Ulf Hermann Reviewed-by: Simon Hausmann Reviewed-by: Frank Meerkoetter Reviewed-by: Shawn Rutledge Reviewed-by: Robin Burchell --- src/quick/util/qquickglobal.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/quick/util/qquickglobal.cpp') diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp index ef54917434..be4c968ab2 100644 --- a/src/quick/util/qquickglobal.cpp +++ b/src/quick/util/qquickglobal.cpp @@ -172,8 +172,8 @@ public: int index = s.indexOf(QLatin1Char(',')); bool xGood, yGood; - float xCoord = s.left(index).toFloat(&xGood); - float yCoord = s.mid(index+1).toFloat(&yGood); + float xCoord = s.leftRef(index).toFloat(&xGood); + float yCoord = s.midRef(index + 1).toFloat(&yGood); if (xGood && yGood) { if (ok) *ok = true; @@ -192,9 +192,9 @@ public: int index2 = s.indexOf(QLatin1Char(','), index+1); bool xGood, yGood, zGood; - float xCoord = s.left(index).toFloat(&xGood); - float yCoord = s.mid(index+1, index2-index-1).toFloat(&yGood); - float zCoord = s.mid(index2+1).toFloat(&zGood); + float xCoord = s.leftRef(index).toFloat(&xGood); + float yCoord = s.midRef(index + 1, index2 - index - 1).toFloat(&yGood); + float zCoord = s.midRef(index2 + 1).toFloat(&zGood); if (xGood && yGood && zGood) { if (ok) *ok = true; @@ -214,10 +214,10 @@ public: int index3 = s.indexOf(QLatin1Char(','), index2+1); bool xGood, yGood, zGood, wGood; - float xCoord = s.left(index).toFloat(&xGood); - float yCoord = s.mid(index+1, index2-index-1).toFloat(&yGood); - float zCoord = s.mid(index2+1, index3-index2-1).toFloat(&zGood); - float wCoord = s.mid(index3+1).toFloat(&wGood); + float xCoord = s.leftRef(index).toFloat(&xGood); + float yCoord = s.midRef(index + 1, index2 - index - 1).toFloat(&yGood); + float zCoord = s.midRef(index2 + 1, index3 - index2 - 1).toFloat(&zGood); + float wCoord = s.midRef(index3 + 1).toFloat(&wGood); if (xGood && yGood && zGood && wGood) { if (ok) *ok = true; @@ -257,10 +257,10 @@ public: if (s.count(QLatin1Char(',')) == 15) { float matValues[16]; bool vOK = true; - QString mutableStr = s; + QStringRef mutableStr(&s); for (int i = 0; vOK && i < 16; ++i) { int cidx = mutableStr.indexOf(QLatin1Char(',')); - matValues[i] = mutableStr.leftRef(cidx).toDouble(&vOK); + matValues[i] = mutableStr.left(cidx).toDouble(&vOK); mutableStr = mutableStr.mid(cidx + 1); } -- cgit v1.2.3