Replace the implementation of splitIntoLines by a new one that does
not need PHP's array_shift which tends to be very slow for arrays with many thousand entries (fixes issue 804).
This commit is contained in:
parent
8db3c45763
commit
b6acf4c0e2
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
- Compatiblity fixes for PostgreSQL (fixes issue 800)
|
- Compatiblity fixes for PostgreSQL (fixes issue 800)
|
||||||
- Fix TOC generation in wiki (issue 803)
|
- Fix TOC generation in wiki (issue 803)
|
||||||
|
- Make the display of large files and diffs faster (fixes issue 804)
|
||||||
|
|
||||||
## Language and Translations
|
## Language and Translations
|
||||||
|
|
||||||
|
@ -147,27 +147,22 @@ class IDF_FileUtil
|
|||||||
* Splits a string into separate lines while retaining the individual
|
* Splits a string into separate lines while retaining the individual
|
||||||
* line ending character for every line.
|
* line ending character for every line.
|
||||||
*
|
*
|
||||||
* OS9 line endings are not supported.
|
|
||||||
*
|
|
||||||
* @param string content
|
* @param string content
|
||||||
* @param boolean if true, skip completely empty lines
|
* @param boolean if true, skip completely empty lines
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function splitIntoLines($content, $skipEmpty = false)
|
public static function splitIntoLines($content, $skipEmpty = false)
|
||||||
{
|
{
|
||||||
$flags = PREG_SPLIT_OFFSET_CAPTURE;
|
$last_off = 0;
|
||||||
if ($skipEmpty) $flags |= PREG_SPLIT_NO_EMPTY;
|
|
||||||
$splitted = preg_split("/\r\n|\n/", $content, -1, $flags);
|
|
||||||
|
|
||||||
$last_off = -1;
|
|
||||||
$lines = array();
|
$lines = array();
|
||||||
while (($split = array_shift($splitted)) !== null) {
|
while (preg_match("/\r\n|\n|\r/", $content, $m, PREG_OFFSET_CAPTURE, $last_off)) {
|
||||||
if ($last_off != -1) {
|
$next_off = strlen($m[0][0]) + $m[0][1];
|
||||||
$lines[] .= substr($content, $last_off, $split[1] - $last_off);
|
$line = substr($content, $last_off, $next_off - $last_off);
|
||||||
}
|
$last_off = $next_off;
|
||||||
$last_off = $split[1];
|
if ($line !== $m[0][0] || !$skipEmpty) $lines[] = $line;
|
||||||
}
|
}
|
||||||
$lines[] = substr($content, $last_off);
|
$line = substr($content, $last_off);
|
||||||
|
if ($line !== false && strlen($line) > 0) $lines[] = $line;
|
||||||
return $lines;
|
return $lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user