minor #18932 Improve memory efficiency (Dword123)

This PR was merged into the 2.7 branch.

Discussion
----------

Improve memory efficiency

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

This avoids concatenating `$message` and `PHP_EOL` (if necessary) as a new value, greatly improving memory efficiency for large `$message`s.

Commits
-------

c1df9f2 Improve memory efficiency
This commit is contained in:
Nicolas Grekas 2016-06-03 13:01:18 +02:00
commit a004fc7526
1 changed files with 1 additions and 1 deletions

View File

@ -70,7 +70,7 @@ class StreamOutput extends Output
*/
protected function doWrite($message, $newline)
{
if (false === @fwrite($this->stream, $message.($newline ? PHP_EOL : ''))) {
if (false === @fwrite($this->stream, $message) || ($newline && (false === @fwrite($this->stream, PHP_EOL)))) {
// should never happen
throw new \RuntimeException('Unable to write output.');
}