Skip to content

Commit

Permalink
Enhance Performance (Microperformance for String Equals Comparison)
Browse files Browse the repository at this point in the history
Replace all checks of mb_strlen is 0 by direct compare to empty string

closes giggsey#444
  • Loading branch information
Philipp Dahse committed Oct 20, 2021
1 parent 76d8106 commit 34c8de2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/AsYouTypeFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ private function attemptToExtractIdd()
*/
private function attemptToExtractCountryCallingCode()
{
if (\mb_strlen($this->nationalNumber) == 0) {
if ($this->nationalNumber === '') {
return false;
}
$numberWithoutCountryCallingCode = '';
Expand Down
16 changes: 8 additions & 8 deletions src/PhoneNumberUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -1917,7 +1917,7 @@ protected function checkRegionForParsing($numberToParse, $defaultRegion)
if (!$this->isValidRegionCode($defaultRegion)) {
// If the number is null or empty, we can't infer the region.
$plusCharsPatternMatcher = new Matcher(static::$PLUS_CHARS_PATTERN, $numberToParse);
if ($numberToParse === null || mb_strlen($numberToParse) == 0 || !$plusCharsPatternMatcher->lookingAt()) {
if ($numberToParse === null || $numberToParse === '' || !$plusCharsPatternMatcher->lookingAt()) {
return false;
}
}
Expand Down Expand Up @@ -1963,7 +1963,7 @@ public function maybeExtractCountryCode(
$keepRawInput,
PhoneNumber $phoneNumber
) {
if (mb_strlen($number) == 0) {
if ($number === '') {
return 0;
}
$fullNumber = $number;
Expand Down Expand Up @@ -2051,7 +2051,7 @@ public function maybeExtractCountryCode(
*/
public function maybeStripInternationalPrefixAndNormalize(&$number, $possibleIddPrefix)
{
if (mb_strlen($number) == 0) {
if ($number === '') {
return CountryCodeSource::FROM_DEFAULT_COUNTRY;
}
$matches = array();
Expand Down Expand Up @@ -2174,7 +2174,7 @@ protected function parsePrefixAsIdd($iddPattern, &$number)
*/
public function extractCountryCode($fullNumber, &$nationalNumber)
{
if ((mb_strlen($fullNumber) == 0) || ($fullNumber[0] == '0')) {
if (($fullNumber === '') || ($fullNumber[0] == '0')) {
// Country codes do not begin with a '0'.
return 0;
}
Expand Down Expand Up @@ -2202,7 +2202,7 @@ public function maybeStripNationalPrefixAndCarrierCode(&$number, PhoneMetadata $
{
$numberLength = mb_strlen($number);
$possibleNationalPrefix = $metadata->getNationalPrefixForParsing();
if ($numberLength == 0 || $possibleNationalPrefix === null || mb_strlen($possibleNationalPrefix) == 0) {
if ($numberLength == 0 || $possibleNationalPrefix === null || $possibleNationalPrefix === '') {
// Early return for numbers of zero length.
return false;
}
Expand All @@ -2219,7 +2219,7 @@ public function maybeStripNationalPrefixAndCarrierCode(&$number, PhoneMetadata $
$numOfGroups = $prefixMatcher->groupCount();
$transformRule = $metadata->getNationalPrefixTransformRule();
if ($transformRule === null
|| mb_strlen($transformRule) == 0
|| $transformRule === ''
|| $prefixMatcher->group($numOfGroups - 1) === null
) {
// If the original number was viable, and the resultant number is not, we return.
Expand Down Expand Up @@ -2870,7 +2870,7 @@ public function formatInOriginalFormat(PhoneNumber $number, $regionCallingFrom)
// compare them easily.
$nationalPrefix = $this->getNddPrefixForRegion($regionCode, true /* strip non-digits */);
$nationalFormat = $this->format($number, PhoneNumberFormat::NATIONAL);
if ($nationalPrefix === null || mb_strlen($nationalPrefix) == 0) {
if ($nationalPrefix === null || $nationalPrefix === '') {
// If the region doesn't have a national prefix at all, we can safely return the national
// format without worrying about a national prefix being added.
$formattedNumber = $nationalFormat;
Expand Down Expand Up @@ -2911,7 +2911,7 @@ public function formatInOriginalFormat(PhoneNumber $number, $regionCallingFrom)
}
$candidateNationalPrefixRule = substr($candidateNationalPrefixRule, 0, $indexOfFirstGroup);
$candidateNationalPrefixRule = static::normalizeDigitsOnly($candidateNationalPrefixRule);
if (mb_strlen($candidateNationalPrefixRule) == 0) {
if ($candidateNationalPrefixRule === '') {
// National prefix not used when formatting this number.
$formattedNumber = $nationalFormat;
break;
Expand Down

0 comments on commit 34c8de2

Please sign in to comment.