mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-27 15:30:42 +00:00
Optimize loop in 'diff-split' case
The "substr( $line, 0, 1 )" expression has already assumed the prefix has length 1. Therefore, it's pointless to compute its length later. The assumption does hold, the only two prefixes the code works with are '+' and '-'. Not changing the check to use str_starts_with now, because it was suggested in I113a8d052b6845852c15969a2f0e6fbbe3e9f8d9 that this shouldn't be done for performance-sensitive code at least until we are on PHP 8. Change-Id: I00cb2fc50ed534bb2bbef3ee1e5f6f466afeeb27
This commit is contained in:
parent
69e23a15f8
commit
d4b15cb7ee
|
@ -179,8 +179,8 @@ class LazyVariableComputer {
|
|||
$diff_lines = explode( "\n", $diff );
|
||||
$result = [];
|
||||
foreach ( $diff_lines as $line ) {
|
||||
if ( substr( $line, 0, 1 ) === $line_prefix ) {
|
||||
$result[] = substr( $line, strlen( $line_prefix ) );
|
||||
if ( ( $line[0] ?? '' ) === $line_prefix ) {
|
||||
$result[] = substr( $line, 1 );
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue