From b8511dc54a776ca7145fa52157765e850b2f8f91 Mon Sep 17 00:00:00 2001 From: Philipp Dahse Date: Wed, 20 Oct 2021 18:52:49 +0200 Subject: [PATCH] Enhance Performance (Microperformance for String Greater Than Comparison) Replace all checks of mb_strlen is greater than 0 by direct compare to not equal to empty string closes #444 --- src/AsYouTypeFormatter.php | 4 ++-- src/PhoneNumberUtil.php | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/AsYouTypeFormatter.php b/src/AsYouTypeFormatter.php index c1215c9c..0f1a0ee6 100644 --- a/src/AsYouTypeFormatter.php +++ b/src/AsYouTypeFormatter.php @@ -500,7 +500,7 @@ private function inputDigitWithOptionToRememberPosition($nextChar, $rememberPosi // See if the accrued digits can be formatted properly already. If not, use the results // from inputDigitHelper, which does formatting based on the formatting pattern chosen. $formattedNumber = $this->attemptToFormatAccruedDigits(); - if (\mb_strlen($formattedNumber) > 0) { + if ($formattedNumber !== '') { return $formattedNumber; } $this->narrowDownPossibleFormats($this->nationalNumber); @@ -663,7 +663,7 @@ private function attemptToChooseFormattingPattern() $this->getAvailableFormats($this->nationalNumber); // See if the accrued digits can be formatted properly already. $formattedNumber = $this->attemptToFormatAccruedDigits(); - if (\mb_strlen($formattedNumber) > 0) { + if ($formattedNumber !== '') { return $formattedNumber; } return $this->maybeCreateNewTemplate() ? $this->inputAccruedNationalNumber() : $this->accruedInput; diff --git a/src/PhoneNumberUtil.php b/src/PhoneNumberUtil.php index 08d096dc..27914246 100644 --- a/src/PhoneNumberUtil.php +++ b/src/PhoneNumberUtil.php @@ -1219,7 +1219,7 @@ public function format(PhoneNumber $number, $numberFormat) // TODO: Consider removing the 'if' above so that unparseable // strings without raw input format to the empty string instead of "+00" $rawInput = $number->getRawInput(); - if (mb_strlen($rawInput) > 0) { + if ($rawInput !== '') { return $rawInput; } } @@ -1668,7 +1668,7 @@ protected function parseHelper($numberToParse, $defaultRegion, $keepRawInput, $c // Attempt to parse extension first, since it doesn't require region-specific data and we want // to have the non-normalised number here. $extension = $this->maybeStripExtension($nationalNumber); - if (mb_strlen($extension) > 0) { + if ($extension !== '') { $phoneNumber->setExtension($extension); } @@ -1744,7 +1744,7 @@ protected function parseHelper($numberToParse, $defaultRegion, $keepRawInput, $c && $validationResult !== ValidationResult::IS_POSSIBLE_LOCAL_ONLY && $validationResult !== ValidationResult::INVALID_LENGTH) { $normalizedNationalNumber = $potentialNationalNumber; - if ($keepRawInput && mb_strlen($carrierCode) > 0) { + if ($keepRawInput && $carrierCode !== '') { $phoneNumber->setPreferredDomesticCarrierCode($carrierCode); } } @@ -2450,7 +2450,7 @@ public function formatNumberForMobileDialing(PhoneNumber $number, $regionCalling // Historically, we set this to an empty string when parsing with raw input if none was // found in the input string. However, this doesn't result in a number we can dial. For this // reason, we treat the empty string the same as if it isn't set at all. - $formattedNumber = mb_strlen($numberNoExt->getPreferredDomesticCarrierCode()) > 0 + $formattedNumber = $numberNoExt->getPreferredDomesticCarrierCode() !== '' ? $this->formatNationalNumberWithPreferredCarrierCode($numberNoExt, '') // Brazilian fixed line and mobile numbers need to be dialed with a carrier code when // called within Brazil. Without that, most of the carriers won't connect the call. @@ -2804,7 +2804,7 @@ public function formatOutOfCountryCallingNumber(PhoneNumber $number, $regionCall PhoneNumberFormat::INTERNATIONAL, $formattedNumber ); - if (mb_strlen($internationalPrefixForFormatting) > 0) { + if ($internationalPrefixForFormatting !== '') { $formattedNumber = $internationalPrefixForFormatting . ' ' . $countryCallingCode . ' ' . $formattedNumber; } else { $this->prefixNumberWithCountryCallingCode(