mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
21ca3123bc
commit
3b7595e8c7
@ -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;
|
||||
|
||||
// We still want to do this even if we have strict path checking for legacy code
|
||||
$var = &$this->data;
|
||||
$diffVar = &$this->changedData;
|
||||
} else {
|
||||
$names = explode('.', $name);
|
||||
|
||||
foreach($names as $n) {
|
||||
$var = &$var[$n];
|
||||
$diffVar = &$diffVar[$n];
|
||||
// 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];
|
||||
}
|
||||
|
||||
$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];
|
||||
|
||||
if(!isset($this->data)) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
$names = explode('.', $name);
|
||||
|
||||
$var = $this->data;
|
||||
|
||||
foreach($names as $n) {
|
||||
if(!isset($var[$n])) {
|
||||
if(!isset($this->data)) {
|
||||
return null;
|
||||
}
|
||||
$var = $var[$n];
|
||||
}
|
||||
|
||||
return $var;
|
||||
$var = $this->data;
|
||||
|
||||
foreach($names as $n) {
|
||||
if(!isset($var[$n])) {
|
||||
return null;
|
||||
}
|
||||
$var = $var[$n];
|
||||
}
|
||||
|
||||
return $var;
|
||||
}
|
||||
}
|
||||
|
||||
public function inst_clear($name) {
|
||||
|
Loading…
Reference in New Issue
Block a user