Skip to content

Commit

Permalink
Enhance Performance (Microperformance for String Greater Than Compari…
Browse files Browse the repository at this point in the history
…son)

Replace all checks of mb_strlen is greater than 0 by direct compare to not equal to empty string

closes giggsey#444
  • Loading branch information
Philipp Dahse committed Oct 20, 2021
1 parent 34c8de2 commit b8511dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/AsYouTypeFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/PhoneNumberUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit b8511dc

Please sign in to comment.