From f8674db931c9b743874ae9d09d5cf48029dcec4b Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Wed, 8 Apr 2020 10:23:40 +0200 Subject: [PATCH] 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. --- smsapp/smshelper.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/smsapp/smshelper.cpp b/smsapp/smshelper.cpp index ea0e0e616..116454dd1 100644 --- a/smsapp/smshelper.cpp +++ b/smsapp/smshelper.cpp @@ -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)