Commit f8674db9 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Don't recreate QRegularExpression for leading zeroes each time

Creating a QRegularExpression is quite expensive and we use the same expression for each run. Sharing it between the runs leads to a significant performance improvement.
parent 43ea8052
Pipeline #17982 failed with stage
in 5 minutes and 11 seconds
......@@ -110,13 +110,15 @@ SmsHelper::CountryCode SmsHelper::determineCountryCode(const QString& canonicalN
QString SmsHelper::canonicalizePhoneNumber(const QString& phoneNumber)
{
static const QRegularExpression leadingZeroes(QStringLiteral("^0*"));
QString toReturn(phoneNumber);
toReturn = toReturn.remove(QStringLiteral(" "));
toReturn = toReturn.remove(QStringLiteral("-"));
toReturn = toReturn.remove(QStringLiteral("("));
toReturn = toReturn.remove(QStringLiteral(")"));
toReturn = toReturn.remove(QStringLiteral("+"));
toReturn = toReturn.remove(QRegularExpression(QStringLiteral("^0*"))); // Strip leading zeroes
toReturn = toReturn.remove(leadingZeroes);
if (toReturn.length() == 0) {
// If we have stripped away everything, assume this is a special number (and already canonicalized)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment