[TASK] Make DiffUtility faster and much more scaleable. 10/22510/2
authorKasper Ligaard <kasperligaard@gmail.com>
Mon, 22 Jul 2013 16:19:49 +0000 (18:19 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Tue, 23 Jul 2013 09:29:50 +0000 (11:29 +0200)
The method DiffUtility->explodeStringIntoWords() calls array_merge()
inside a loop. The cost of constantly doing a function invocation and
merging arrays needlessly slows the method and the whole diff utility.
Moving the array merging outside the loop, the method becomes faster
and able to handle much larger input.

Change-Id: I4c2d21cff9b18392e89e316fec9dc615e715a073
Resolves: #50318
Releases: 6.2, 6.1, 6.0
Reviewed-on: https://review.typo3.org/22510
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/core/Classes/Utility/DiffUtility.php

index 9c21292..c1114ba 100644 (file)
@@ -197,11 +197,11 @@ class DiffUtility {
                $outArray = array();
                foreach ($strArr as $lineOfWords) {
                        $allWords = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(' ', $lineOfWords, 1);
-                       $outArray = array_merge($outArray, $allWords);
-                       $outArray[] = '';
-                       $outArray[] = '';
+                       $outArray[] = $allWords;
+                       $outArray[] = array('');
+                       $outArray[] = array('');
                }
-               return $outArray;
+               return call_user_func_array('array_merge', $outArray);
        }
 
        /**
@@ -224,4 +224,4 @@ class DiffUtility {
 }
 
 
-?>
\ No newline at end of file
+?>