Indefero

Indefero Commit Details


Date:2012-05-03 17:48:53 (12 years 7 months ago)
Author:Thomas Keller
Branch:develop, release-1.3
Commit:b6acf4c0e20738fd224ae28a392b029221c89f95
Parents: 8db3c45763d22b8363ef8b425035358c172d0acb
Message: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).

Changes:

File differences

NEWS.mdtext
44
55
66
7
78
89
910
- Compatiblity fixes for PostgreSQL (fixes issue 800)
- Fix TOC generation in wiki (issue 803)
- Make the display of large files and diffs faster (fixes issue 804)
## Language and Translations
src/IDF/FileUtil.php
147147
148148
149149
150
151
152150
153151
154152
155153
156154
157155
158
159
160
161
162
156
163157
164
165
166
167
168
158
159
160
161
162
169163
170
164
165
171166
172167
173168
* Splits a string into separate lines while retaining the individual
* line ending character for every line.
*
* OS9 line endings are not supported.
*
* @param string content
* @param boolean if true, skip completely empty lines
* @return string
*/
public static function splitIntoLines($content, $skipEmpty = false)
{
$flags = PREG_SPLIT_OFFSET_CAPTURE;
if ($skipEmpty) $flags |= PREG_SPLIT_NO_EMPTY;
$splitted = preg_split("/\r\n|\n/", $content, -1, $flags);
$last_off = -1;
$last_off = 0;
$lines = array();
while (($split = array_shift($splitted)) !== null) {
if ($last_off != -1) {
$lines[] .= substr($content, $last_off, $split[1] - $last_off);
}
$last_off = $split[1];
while (preg_match("/\r\n|\n|\r/", $content, $m, PREG_OFFSET_CAPTURE, $last_off)) {
$next_off = strlen($m[0][0]) + $m[0][1];
$line = substr($content, $last_off, $next_off - $last_off);
$last_off = $next_off;
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;
}

Archive Download the corresponding diff file

Page rendered in 0.07929s using 14 queries.