DairikiDiff: Optimise method WordLevelDiff._split()
authorBoris Nagaev <bnagaev@gmail.com>
Thu, 2 May 2013 14:33:15 +0000 (18:33 +0400)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 16 May 2013 23:01:09 +0000 (23:01 +0000)
_split() copied two arrays N times, where N is number of lines in diff.
This was done by $a = array_merge($a, ...);
Instead of doing this, new words are appended to the end of array
using []= syntax.

Bug: 47989
Change-Id: I41338a2a82fbc20d7511f4c79581880febeeeea5

includes/diff/DairikiDiff.php

index 4435fc6..174c1d6 100644 (file)
@@ -1284,8 +1284,12 @@ class WordLevelDiff extends MappedDiff {
                                if ( preg_match_all( '/ ( [^\S\n]+ | [0-9_A-Za-z\x80-\xff]+ | . ) (?: (?!< \n) [^\S\n])? /xs',
                                        $line, $m ) )
                                {
-                                       $words = array_merge( $words, $m[0] );
-                                       $stripped = array_merge( $stripped, $m[1] );
+                                       foreach ( $m[0] as $word ) {
+                                               $words[] = $word;
+                                       }
+                                       foreach ( $m[1] as $stripped_word ) {
+                                               $stripped[] = $stripped_word;
+                                       }
                                }
                        }
                }