mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-23 22:45:20 +00:00
Avoid counting arrays if not needed
count() tends to be one of the slowest PHP functions and should be avoided, especially if the actual number of elements is not needed. Change-Id: Ia979c481f898d2fccedb0ed127417ef05ba7ff38
This commit is contained in:
parent
a22434e195
commit
c00cf4a204
|
@ -525,7 +525,7 @@ class Cite {
|
|||
case 'new':
|
||||
# Rollback the addition of new elements to the stack.
|
||||
unset( $this->mRefs[$group][$key] );
|
||||
if ( count( $this->mRefs[$group] ) === 0 ) {
|
||||
if ( $this->mRefs[$group] === array() ) {
|
||||
unset( $this->mRefs[$group] );
|
||||
unset( $this->mGroupCnt[$group] );
|
||||
}
|
||||
|
@ -592,7 +592,7 @@ class Cite {
|
|||
# Mostly a side effect of using #tag to call references
|
||||
$count = substr_count( $str, Parser::MARKER_PREFIX . "-ref-" );
|
||||
for ( $i = 1; $i <= $count; $i++ ) {
|
||||
if ( count( $this->mRefCallStack ) < 1 ) {
|
||||
if ( !$this->mRefCallStack ) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -623,10 +623,10 @@ class Cite {
|
|||
$this->mRefCallStack = array();
|
||||
}
|
||||
|
||||
if ( count( $argv ) && $wgAllowCiteGroups ) {
|
||||
if ( $argv && $wgAllowCiteGroups ) {
|
||||
return $this->error( 'cite_error_references_invalid_parameters_group' );
|
||||
}
|
||||
if ( count( $argv ) ) {
|
||||
if ( $argv ) {
|
||||
return $this->error( 'cite_error_references_invalid_parameters' );
|
||||
}
|
||||
|
||||
|
@ -636,7 +636,7 @@ class Cite {
|
|||
}
|
||||
|
||||
# Append errors generated while processing <references>
|
||||
if ( count( $this->mReferencesErrors ) > 0 ) {
|
||||
if ( $this->mReferencesErrors ) {
|
||||
$s .= "\n" . implode( "<br />\n", $this->mReferencesErrors );
|
||||
$this->mReferencesErrors = array();
|
||||
}
|
||||
|
@ -651,7 +651,7 @@ class Cite {
|
|||
* @return string XHTML ready for output
|
||||
*/
|
||||
function referencesFormat( $group ) {
|
||||
if ( ( count( $this->mRefs ) === 0 ) || ( empty( $this->mRefs[$group] ) ) ) {
|
||||
if ( !$this->mRefs || !$this->mRefs[$group] ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
@ -1083,7 +1083,7 @@ class Cite {
|
|||
}
|
||||
|
||||
foreach ( $this->mRefs as $group => $refs ) {
|
||||
if ( count( $refs ) === 0 ) {
|
||||
if ( !$refs ) {
|
||||
continue;
|
||||
}
|
||||
if ( $group === self::DEFAULT_GROUP ) {
|
||||
|
|
Loading…
Reference in a new issue