Git commit a2c6bf4c0c98465a0afe88bd882e3cee7afe4696 by Arjen Hiemstra, on b= ehalf of Boudewijn Rempt. Committed on 21/11/2013 at 16:16. Pushed by ahiemstra into branch 'calligra-qt5-rempt'. Optimize splitToRowAndColumn by not creating so many temporary qstrings M +23 -15 filters/sheets/xlsx/XlsxXmlWorksheetReader.cpp http://commits.kde.org/calligra/a2c6bf4c0c98465a0afe88bd882e3cee7afe4696 diff --git a/filters/sheets/xlsx/XlsxXmlWorksheetReader.cpp b/filters/sheet= s/xlsx/XlsxXmlWorksheetReader.cpp index 6ad976e..b212bb0 100644 --- a/filters/sheets/xlsx/XlsxXmlWorksheetReader.cpp +++ b/filters/sheets/xlsx/XlsxXmlWorksheetReader.cpp @@ -127,18 +127,20 @@ XlsxXmlWorksheetReaderContext::~XlsxXmlWorksheetReade= rContext() delete sheet; } = -static void splitToRowAndColumn(const QString source, QString& row, int& c= olumn) +static void splitToRowAndColumn(const char *source, int sourceStart, int s= ourceLength, QString& row, int& column) { - // Checking whether the 2nd char is a number - const char second =3D source.at(1).toLatin1(); - if (second < 65) { - row =3D source.at(0); - column =3D source.mid(1).toInt(); - } - else { - row =3D source.left(2); - column =3D source.mid(2).toInt(); + // find the position of the first number + int pos =3D 0; + while (pos < sourceLength) { + if (source[sourceStart + pos] < 65) { + break; + } + row.append(source[sourceStart + pos]); + pos++; } + + char *pEnd =3D 0; + column =3D strtol(source + sourceStart + pos, &pEnd, 10); } = //! @return value @a cm with cm suffix @@ -166,6 +168,9 @@ QList > XlsxXmlWorksheetReaderCo= ntext::conditionalStyleFo = int index =3D 0; while (index < conditionalStyles.size()) { + startLetter.clear(); + endLetter.clear(); + QString range =3D conditionalStyles.at(index).first; if (cachedHits.contains(range)) { if (!addedConditions.contains(conditionalStyles.at(index).seco= nd.value("style:condition"))) { @@ -179,14 +184,17 @@ QList > XlsxXmlWorksheetReader= Context::conditionalStyleFo ++index; continue; } - int columnIndex =3D range.indexOf(':'); + + QByteArray ba =3D range.toLatin1(); + + int columnIndex =3D ba.indexOf(':'); if (columnIndex < 0) { - splitToRowAndColumn(range, startLetter, startNumber); + splitToRowAndColumn(ba.constData(), 0, ba.length(), startLette= r, startNumber); endLetter.clear(); } else { - splitToRowAndColumn(range.left(columnIndex), startLetter, star= tNumber); - splitToRowAndColumn(range.mid(columnIndex + 1), endLetter, end= Number); + splitToRowAndColumn(ba.constData(), 0, columnIndex, startLette= r, startNumber); + splitToRowAndColumn(ba.constData(), columnIndex + 1, ba.size()= - (columnIndex + 1), endLetter, endNumber); } = if ((positionLetter =3D=3D startLetter && positionNumber =3D=3D st= artNumber && endLetter.isEmpty()) || @@ -1495,7 +1503,7 @@ KoFilter::ConversionStatus XlsxXmlWorksheetReader::re= ad_c() if (!m_context->conditionalStyles.isEmpty()) { QString positionLetter; int positionNumber; - splitToRowAndColumn(r, positionLetter, positionNumber); + splitToRowAndColumn(r.toLatin1().constData(), 0, r.size(), pos= itionLetter, positionNumber); QList > maps =3D m_context->conditional= StyleForPosition(positionLetter, positionNumber); int index =3D maps.size(); // Adding the lists in reversed priority order, as KoGenStyle = when creating the style