LanguageNameSearch.php: Minor cleanup

Change-Id: If031c59fee64ad6e51dedd3328aec7eca6ed0019
This commit is contained in:
Reedy
2021-11-25 23:33:01 +00:00
committed by jenkins-bot
parent 72c8cdb40b
commit b7e881be0a

View File

@@ -63,13 +63,10 @@ class LanguageNameSearch {
}
$index = self::getIndex( $searchKey );
$bucketsForIndex = [];
if ( isset( LanguageNameSearchData::$buckets[$index] ) ) {
$bucketsForIndex = LanguageNameSearchData::$buckets[$index];
}
$bucketsForIndex = LanguageNameSearchData::$buckets[$index] ?? [];
// types are 'prefix', 'infix' (in this order!)
foreach ( $bucketsForIndex as $bucketType => $bucket ) {
foreach ( $bucketsForIndex as $bucket ) {
foreach ( $bucket as $name => $code ) {
// We can skip checking languages we already have in the list
if ( isset( $results[ $code ] ) ) {
@@ -119,10 +116,10 @@ class LanguageNameSearch {
if ( $codepoint < 4000 ) {
// For latin etc. we need smaller buckets for speed
return $codepoint;
} else {
// Try to group names of same script together
return $codepoint - ( $codepoint % 1000 );
}
// Try to group names of same script together
return $codepoint - ( $codepoint % 1000 );
}
/**
@@ -143,27 +140,27 @@ class LanguageNameSearch {
$number = $thisValue;
break;
} else {
// Codepoints larger than 127 are represented by multi-byte sequences
if ( $values === [] ) {
// 224 is the lowest non-overlong-encoded codepoint.
$lookingFor = ( $thisValue < 224 ) ? 2 : 3;
}
// Codepoints larger than 127 are represented by multi-byte sequences
if ( $values === [] ) {
// 224 is the lowest non-overlong-encoded codepoint.
$lookingFor = ( $thisValue < 224 ) ? 2 : 3;
}
$values[] = $thisValue;
if ( count( $values ) === $lookingFor ) {
// Refer http://en.wikipedia.org/wiki/UTF-8#Description
if ( $lookingFor === 3 ) {
$number = ( $values[0] % 16 ) * 4096;
$number += ( $values[1] % 64 ) * 64;
$number += $values[2] % 64;
} else {
$number = ( $values[0] % 32 ) * 64;
$number += $values[1] % 64;
}
$values[] = $thisValue;
if ( count( $values ) === $lookingFor ) {
// Refer http://en.wikipedia.org/wiki/UTF-8#Description
if ( $lookingFor === 3 ) {
$number = ( $values[0] % 16 ) * 4096;
$number += ( $values[1] % 64 ) * 64;
$number += $values[2] % 64;
} else {
$number = ( $values[0] % 32 ) * 64;
$number += $values[1] % 64;
}
break;
}
break;
}
}