r48667 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48666‎ | r48667 | r48668 >
Date:02:39, 22 March 2009
Author:werdna
Status:ok
Tags:
Comment:
Optimise rmdoubles by replacing its entire code with a single regex. Benchmarking shows it's up to 20 times faster.
Modified paths:
  • /trunk/extensions/AbuseFilter/AbuseFilter.parser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AbuseFilter/AbuseFilter.parser.php
@@ -1118,18 +1118,7 @@
11191119 }
11201120
11211121 protected function rmdoubles( $s ) {
1122 - $last = -1;
1123 - $ret = array();
1124 -
1125 - $chars = AntiSpoof::stringToList( $s );
1126 -
1127 - foreach( $chars as $char) {
1128 - if ($char != $last)
1129 - $ret[] = $char;
1130 - $last = $char;
1131 - }
1132 -
1133 - return AntiSpoof::listToString($ret);
 1122+ return preg_replace( '/(.)\1+/us','\1',$s);
11341123 }
11351124
11361125 protected function rmwhitespace( $s ) {

Status & tagging log