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.
This commit is contained in:
parent
43ea8052fe
commit
f8674db931
1 changed files with 3 additions and 1 deletions
|
@ -110,13 +110,15 @@ SmsHelper::CountryCode SmsHelper::determineCountryCode(const QString& canonicalN
|
||||||
|
|
||||||
QString SmsHelper::canonicalizePhoneNumber(const QString& phoneNumber)
|
QString SmsHelper::canonicalizePhoneNumber(const QString& phoneNumber)
|
||||||
{
|
{
|
||||||
|
static const QRegularExpression leadingZeroes(QStringLiteral("^0*"));
|
||||||
|
|
||||||
QString toReturn(phoneNumber);
|
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(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 (toReturn.length() == 0) {
|
||||||
// If we have stripped away everything, assume this is a special number (and already canonicalized)
|
// If we have stripped away everything, assume this is a special number (and already canonicalized)
|
||||||
|
|
Loading…
Reference in a new issue