Rearrange Cite::listToText for performance

The two message are not needed in case there is only one element.
Since fetching messages is a little expensive, I feel it's worth
rearranging this code.

Or not, because it seems this method is never called with one
element only.

Change-Id: Ie915278b41f053afe0d14a29d2aec54c98e5185e
This commit is contained in:
Thiemo Kreuz (WMDE) 2018-11-19 16:40:39 +01:00 committed by Umherirrender
parent 1fe6947693
commit 8760fe5e62

View file

@ -1097,17 +1097,15 @@ class Cite {
*/
private function listToText( $arr ) {
$cnt = count( $arr );
$sep = wfMessage( 'cite_references_link_many_sep' )->inContentLanguage()->plain();
$and = wfMessage( 'cite_references_link_many_and' )->inContentLanguage()->plain();
if ( $cnt === 1 ) {
// Enforce always returning a string
return (string)$arr[0];
} else {
$t = array_slice( $arr, 0, $cnt - 1 );
return implode( $sep, $t ) . $and . $arr[$cnt - 1];
}
$sep = wfMessage( 'cite_references_link_many_sep' )->inContentLanguage()->plain();
$and = wfMessage( 'cite_references_link_many_and' )->inContentLanguage()->plain();
$t = array_slice( $arr, 0, $cnt - 1 );
return implode( $sep, $t ) . $and . $arr[$cnt - 1];
}
/**