Skip to content

Commit

Permalink
Pass this by reference to avoid making copies of the array.
Browse files Browse the repository at this point in the history
This array can contain large amounts of body text, avoid copying it.
  • Loading branch information
mrubinsk committed May 5, 2015
1 parent 546e8bb commit 51b2f06
Showing 1 changed file with 7 additions and 6 deletions.
Expand Up @@ -539,7 +539,8 @@ protected function _getBodyPart(
public function plainBody()
{
if (!empty($this->_plain) && empty($this->_validatedPlain)) {
$this->_validatedPlain = $this->_validateBodyData($this->_plain);
$this->_validateBodyData($this->_plain);
$this->_validatedPlain = $this->_plain;
}
if ($this->_validatedPlain) {
return $this->_validatedPlain;
Expand All @@ -560,7 +561,8 @@ public function plainBody()
public function htmlBody()
{
if (!empty($this->_html) && empty($this->_validatedHtml)) {
$this->_validatedHtml = $this->_validateBodyData($this->_html);
$this->_validateBodyData($this->_html);
$this->_validatedHtml = $this->_html;
}
if ($this->_validatedHtml) {
return $this->_validatedHtml;
Expand All @@ -581,7 +583,8 @@ public function htmlBody()
public function bodyPartBody()
{
if (!empty($this->_bodyPart)) {
return $this->_validateBodyData($this->_bodyPart);
$this->_validateBodyData($this->_bodyPart);
return $this->_bodyPart;
}

return false;
Expand All @@ -596,16 +599,14 @@ public function bodyPartBody()
*
* @return array The validated body data array. @see self::_bodyPartText()
*/
protected function _validateBodyData($data)
protected function _validateBodyData(&$data)
{
$stream = new Horde_Stream_Temp(array('max_memory' => 1048576));
$filter_h = stream_filter_append($stream->stream, 'horde_eol', STREAM_FILTER_WRITE);
$stream->add(Horde_ActiveSync_Utils::ensureUtf8($data['body'], $data['charset']), true);
stream_filter_remove($filter_h);

$data['body'] = $stream;

return $data;
}

/**
Expand Down

0 comments on commit 51b2f06

Please sign in to comment.