roundcube/roundcubemail — pull request #128 by kevinanties (2013-09-21 15:38:14+00:00)
Title: Speed up session decode and encode function

The below unserialize function is at least twice faster than current one.

At rcube_session.php:

private function serialize($vars)
{
$old = $_SESSION;
$_SESSION = $vars;
$data = session_encode();
$_SESSION = $old;
return $data;
}

private function unserialize($str)
{
$data = array();
$offset = 0;
$len = strlen($str);
while ($offset < $len) {
$pos = strpos($str, "|", $offset);
if($pos === false)
break;
$num = $pos - $offset;
$varname = substr($str, $offset, $num);
$offset += $num + 1;
$part = unserialize(substr($str, $offset));
if($part === false)
break;
$data[$varname] = $part;
$offset += strlen(serialize($part));
}
return $data;
}

Also, at line ~217, i think it can change from

$newvars = $this->serialize(array_merge(
(array)$a_oldvars, (array)$this->unserialize($vars)));

to

$newvars = $this->serialize(array_merge(
(array)$a_oldvars, $_SESSION));