From: Timo Tijhof Date: Sat, 31 Aug 2019 21:16:08 +0000 (+0100) Subject: ProxyLookup: Optimise in_array in isConfiguredProxy() X-Git-Tag: 1.34.0-rc.0~432^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=commitdiff_plain;h=a11863a0af42a360ea5eab7669b742fbc72f1b35;p=lhc%2Fweb%2Fwiklou.git ProxyLookup: Optimise in_array in isConfiguredProxy() This is called on all page loads by WebRequest::getIP(), from Setup.php. Strict in_array can easily make it 4 times faster (reduce by 75%). For example, with an array containing 5 short strings and looking up a 6th similar string that is not in the list, repeated 100x: loose: 2.410 ms, 2.731 ms, 2.367 ms strict: 0.649 ms, 0.668 ms, 0.653 ms The larger the array to search through, the bigger the difference becomes as it speeds up each internal comparison. (PHP 7.2.20) Bug: T189966 Change-Id: I6742dfa0a6d44b15294695b15ffe4885cb6a5310 --- diff --git a/includes/ProxyLookup.php b/includes/ProxyLookup.php index 246ae95ae9..7450bb91dc 100644 --- a/includes/ProxyLookup.php +++ b/includes/ProxyLookup.php @@ -58,7 +58,7 @@ class ProxyLookup { */ public function isConfiguredProxy( $ip ) { // Quick check of known singular proxy servers - if ( in_array( $ip, $this->proxyServers ) ) { + if ( in_array( $ip, $this->proxyServers, true ) ) { return true; }