ENHANCEMENT: Improved performance of Session::set() and Session::get() when there are no .s in the name

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@83438 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-07-31 05:38:50 +00:00
parent 21ca3123bc
commit 3b7595e8c7

View File

@ -83,19 +83,26 @@ class Session {
}
public function inst_set($name, $val) {
$names = explode('.', $name);
// Quicker execution path for "."-free names
if(strpos($name,'.') === false) {
$this->data[$name] = $val;
$this->changedData[$name] = $val;
} else {
$names = explode('.', $name);
// We still want to do this even if we have strict path checking for legacy code
$var = &$this->data;
$diffVar = &$this->changedData;
// We still want to do this even if we have strict path checking for legacy code
$var = &$this->data;
$diffVar = &$this->changedData;
foreach($names as $n) {
$var = &$var[$n];
$diffVar = &$diffVar[$n];
foreach($names as $n) {
$var = &$var[$n];
$diffVar = &$diffVar[$n];
}
$var = $val;
$diffVar = $val;
}
$var = $val;
$diffVar = $val;
}
public function inst_addToArray($name, $val) {
@ -115,22 +122,28 @@ class Session {
}
public function inst_get($name) {
$names = explode('.', $name);
// Quicker execution path for "."-free names
if(strpos($name,'.') === false) {
if(isset($this->data[$name])) return $this->data[$name];
} else {
$names = explode('.', $name);
if(!isset($this->data)) {
return null;
}
$var = $this->data;
foreach($names as $n) {
if(!isset($var[$n])) {
if(!isset($this->data)) {
return null;
}
$var = $var[$n];
}
$var = $this->data;
return $var;
foreach($names as $n) {
if(!isset($var[$n])) {
return null;
}
$var = $var[$n];
}
return $var;
}
}
public function inst_clear($name) {