jenkins-bot has submitted this change and it was merged.
Change subject: Avoid counting arrays if not needed
......................................................................
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.
empty() is well defined for variables that are guaranteed to be an
array (or null).
empty() should be avoided on strings, but this is not the case in
this patch.
Change-Id: I5e01fe5d3fbcf0f32e602283075bb5967748c02a
---
M includes/Searcher.php
1 file changed, 7 insertions(+), 6 deletions(-)
Approvals:
Cindy-the-browser-test-bot: Looks good to me, but someone else must approve
EBernhardson: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/Searcher.php b/includes/Searcher.php
index 214f54a..1f150ff 100644
--- a/includes/Searcher.php
+++ b/includes/Searcher.php
@@ -1167,7 +1167,7 @@
$wgCirrusSearchSearchShardTimeout,
$wgCirrusSearchClientSideSearchTimeout;
- if ( sizeof( $this->nonTextQueries ) > 0 ) {
+ if ( $this->nonTextQueries ) {
$bool = new \Elastica\Query\Bool();
if ( $this->query !== null ) {
$bool->addMust( $this->query );
@@ -1221,7 +1221,7 @@
return $field[ 'type' ] !== 'plain';
});
}
- if ( sizeof( $this->nonTextHighlightQueries ) > 0 ) {
+ if ( !empty( $this->nonTextHighlightQueries ) ) {
// We have some phrase_prefix queries, so let's
include them in the
// generated highlight_query.
$bool = new \Elastica\Query\Bool();
@@ -1250,10 +1250,11 @@
}
if ( $this->sort != 'relevance' ) {
+ // Clear rescores if we aren't using relevance as the
search sort because they aren't used.
$this->rescore = array();
}
- if ( count( $this->rescore ) ) {
+ if ( $this->rescore ) {
// rescore_query has to be in array form before we send
it to Elasticsearch but it is way easier to work
// with if we leave it in query for until now
$modifiedRescore = array();
@@ -1405,7 +1406,7 @@
}
/**
- * @return int[]
+ * @return int[]|null
*/
public function getNamespaces() {
return $this->namespaces;
@@ -1765,7 +1766,7 @@
}
// Add boosts for namespaces
- $namespacesToBoost = $this->namespaces === null ?
MWNamespace::getValidNamespaces() : $this->namespaces;
+ $namespacesToBoost = $this->namespaces ?:
MWNamespace::getValidNamespaces();
if ( $namespacesToBoost ) {
// Group common weights together and build a single
filter per weight
// to save on filters.
@@ -1940,7 +1941,7 @@
return;
}
$foundNamespace = $foundNamespace->getValue();
- if ( count( $foundNamespace ) == 0 ) {
+ if ( !$foundNamespace ) {
return;
}
$foundNamespace = $foundNamespace[ 0 ];
--
To view, visit https://gerrit.wikimedia.org/r/208920
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5e01fe5d3fbcf0f32e602283075bb5967748c02a
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Cindy-the-browser-test-bot <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: Manybubbles <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: WMDE-Fisch <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits