Skip to content

Commit b8511dc

Browse files
author
Philipp Dahse
committed
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 giggsey#444
1 parent 34c8de2 commit b8511dc

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/AsYouTypeFormatter.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ private function inputDigitWithOptionToRememberPosition($nextChar, $rememberPosi
500500
// See if the accrued digits can be formatted properly already. If not, use the results
501501
// from inputDigitHelper, which does formatting based on the formatting pattern chosen.
502502
$formattedNumber = $this->attemptToFormatAccruedDigits();
503-
if (\mb_strlen($formattedNumber) > 0) {
503+
if ($formattedNumber !== '') {
504504
return $formattedNumber;
505505
}
506506
$this->narrowDownPossibleFormats($this->nationalNumber);
@@ -663,7 +663,7 @@ private function attemptToChooseFormattingPattern()
663663
$this->getAvailableFormats($this->nationalNumber);
664664
// See if the accrued digits can be formatted properly already.
665665
$formattedNumber = $this->attemptToFormatAccruedDigits();
666-
if (\mb_strlen($formattedNumber) > 0) {
666+
if ($formattedNumber !== '') {
667667
return $formattedNumber;
668668
}
669669
return $this->maybeCreateNewTemplate() ? $this->inputAccruedNationalNumber() : $this->accruedInput;

src/PhoneNumberUtil.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ public function format(PhoneNumber $number, $numberFormat)
12191219
// TODO: Consider removing the 'if' above so that unparseable
12201220
// strings without raw input format to the empty string instead of "+00"
12211221
$rawInput = $number->getRawInput();
1222-
if (mb_strlen($rawInput) > 0) {
1222+
if ($rawInput !== '') {
12231223
return $rawInput;
12241224
}
12251225
}
@@ -1668,7 +1668,7 @@ protected function parseHelper($numberToParse, $defaultRegion, $keepRawInput, $c
16681668
// Attempt to parse extension first, since it doesn't require region-specific data and we want
16691669
// to have the non-normalised number here.
16701670
$extension = $this->maybeStripExtension($nationalNumber);
1671-
if (mb_strlen($extension) > 0) {
1671+
if ($extension !== '') {
16721672
$phoneNumber->setExtension($extension);
16731673
}
16741674

@@ -1744,7 +1744,7 @@ protected function parseHelper($numberToParse, $defaultRegion, $keepRawInput, $c
17441744
&& $validationResult !== ValidationResult::IS_POSSIBLE_LOCAL_ONLY
17451745
&& $validationResult !== ValidationResult::INVALID_LENGTH) {
17461746
$normalizedNationalNumber = $potentialNationalNumber;
1747-
if ($keepRawInput && mb_strlen($carrierCode) > 0) {
1747+
if ($keepRawInput && $carrierCode !== '') {
17481748
$phoneNumber->setPreferredDomesticCarrierCode($carrierCode);
17491749
}
17501750
}
@@ -2450,7 +2450,7 @@ public function formatNumberForMobileDialing(PhoneNumber $number, $regionCalling
24502450
// Historically, we set this to an empty string when parsing with raw input if none was
24512451
// found in the input string. However, this doesn't result in a number we can dial. For this
24522452
// reason, we treat the empty string the same as if it isn't set at all.
2453-
$formattedNumber = mb_strlen($numberNoExt->getPreferredDomesticCarrierCode()) > 0
2453+
$formattedNumber = $numberNoExt->getPreferredDomesticCarrierCode() !== ''
24542454
? $this->formatNationalNumberWithPreferredCarrierCode($numberNoExt, '')
24552455
// Brazilian fixed line and mobile numbers need to be dialed with a carrier code when
24562456
// called within Brazil. Without that, most of the carriers won't connect the call.
@@ -2804,7 +2804,7 @@ public function formatOutOfCountryCallingNumber(PhoneNumber $number, $regionCall
28042804
PhoneNumberFormat::INTERNATIONAL,
28052805
$formattedNumber
28062806
);
2807-
if (mb_strlen($internationalPrefixForFormatting) > 0) {
2807+
if ($internationalPrefixForFormatting !== '') {
28082808
$formattedNumber = $internationalPrefixForFormatting . ' ' . $countryCallingCode . ' ' . $formattedNumber;
28092809
} else {
28102810
$this->prefixNumberWithCountryCallingCode(

0 commit comments

Comments
 (0)