src/DiffToolkit.php
protected function linesToCharsMunge($text, array &$lineArray, array &$lineHash)
    {
        // Simple string concat is even faster than implode() in PHP.
        $chars = '';

        $delimiter = iconv('UTF-8', mb_internal_encoding(), "\n");

        // TODO optimize code
        // explode('\n', $text) would temporarily double our memory footprint,
        // but mb_strpos() and mb_substr() work too slow
        $lines = explode($delimiter, $text);

        $last_line_has_delimiter = end($lines) === '';
        if ($last_line_has_delimiter) {
            array_pop($lines);
        }

        foreach ($lines as $i => $line) {
            if (isset($lines[$i + 1]) || $last_line_has_delimiter) {
                $line .= $delimiter;
            }
            if (!isset($lineHash[$line])) {
                $lineArray[] = $line;
                $lineHash[$line] = count($lineArray) - 1;
            }
            $chars .= Utils::unicodeChr($lineHash[$line]);
        }

        return $chars;
    }
protected function linesToCharsMunge($text, array &$lineArray, array &$lineHash)
    {
        // Simple string concat is even faster than implode() in PHP.
        $chars = '';

        $delimiter = iconv('UTF-8', mb_internal_encoding(), "\n");

        // TODO optimize code
        // explode('\n', $text) would temporarily double our memory footprint,
        // but mb_strpos() and mb_substr() work too slow
        $lines = explode($delimiter, $text);

        $last_line_has_delimiter = end($lines) === '';
        if ($last_line_has_delimiter) {
            array_pop($lines);
        }

        foreach ($lines as $i => $line) {
            if (isset($lines[$i + 1]) || $last_line_has_delimiter) {
                $line .= $delimiter;
            }
            if (!isset($lineHash[$line])) {
                $lineArray[] = $line;
                $lineHash[$line] = count($lineArray) - 1;
            }
            $chars .= Utils::unicodeChr($lineHash[$line]);
        }

        return $chars;
    }
Split a text into an array of strings.  Reduce the texts to a string of hashes where each
Unicode character represents one line.
Modifies $lineArray and $lineHash. TODO try to fix it!

@param string $text String to encode.
@param array  $lineArray
@param array  $lineHash

@return string Encoded string.