Skip to content

Commit

Permalink
Tweak: determine whether to not store small literals in streams at re…
Browse files Browse the repository at this point in the history
…ad time also
  • Loading branch information
slusarz committed May 6, 2015
1 parent 35e5ad4 commit 50a2358
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,14 @@ public function read($size = null)

while (($literal_len > 0) && !feof($this->_stream)) {
$in = fread($this->_stream, min($literal_len, 8192));
$token->addLiteralStream($in);
/* Only store in stream if this is something more than a
* nominal number of bytes. */
if ($old_len > 256) {
$token->addLiteralStream($in);
} else {
$token->add($in);
}

if (!empty($this->_params['debugliteral'])) {
$this->_params['debug']->raw($in);
}
Expand Down
36 changes: 17 additions & 19 deletions framework/Imap_Client/lib/Horde/Imap/Client/Tokenize.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,26 +301,24 @@ public function next()

case '{':
$literal_len = intval($this->_stream->getToChar('}'));
if ($this->literalStream) {
$pos = $this->_stream->pos();
if (isset($this->_literals[$pos])) {
$text = $this->_literals[$pos];
} elseif ($literal_len > self::MIN_LITERAL_STREAM) {
$text = new Horde_Stream_Temp();
while (($literal_len > 0) && !feof($stream)) {
$part = $this->_stream->substring(
0,
min($literal_len, 8192)
);
$text->add($part);
$literal_len -= strlen($part);
}
} else {
$text = false;
$pos = $this->_stream->pos();
if (isset($this->_literals[$pos])) {
$text = $this->_literals[$pos];
if (!$this->literalStream) {
$text = strval($text);
}
}

if ($text === false) {
} elseif ($this->literalStream &&
($literal_len > self::MIN_LITERAL_STREAM)) {
$text = new Horde_Stream_Temp();
while (($literal_len > 0) && !feof($stream)) {
$part = $this->_stream->substring(
0,
min($literal_len, 8192)
);
$text->add($part);
$literal_len -= strlen($part);
}
} else {
$text = $this->_stream->substring(0, $literal_len);
}
$check_len = false;
Expand Down

0 comments on commit 50a2358

Please sign in to comment.