From 46b965edba6f0238b08baeb69b0f512171bc8e5b Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 21 Nov 2009 19:57:04 -0500 Subject: [PATCH] Refactoring Configure::read/Configure::write so keys with <= 2 keys read/write faster. --- cake/libs/configure.php | 44 +++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/cake/libs/configure.php b/cake/libs/configure.php index b6feb080ac3..7cc3988cc61 100644 --- a/cake/libs/configure.php +++ b/cake/libs/configure.php @@ -91,11 +91,21 @@ function write($config, $value = null) { if (strpos($name, '.') === false) { $_this->{$name} = $value; } else { - $names = explode('.', $name, 2); - if (!isset($_this->{$names[0]})) { - $_this->{$names[0]} = array(); + $names = explode('.', $name, 4); + switch (count($names)) { + case 2: + $_this->{$names[0]}[$names[1]] = $value; + break; + case 3: + $_this->{$names[0]}[$names[1]][$names[2]] = $value; + case 4: + $names = explode('.', $name, 2); + if (!isset($_this->{$names[0]})) { + $_this->{$names[0]} = array(); + } + $_this->{$names[0]} = Set::insert($_this->{$names[0]}, $names[1], $value); + break; } - $_this->{$names[0]} = Set::insert($_this->{$names[0]}, $names[1], $value); } } @@ -149,18 +159,32 @@ function read($var = 'debug') { } if (strpos($var, '.') !== false) { - $names = explode('.', $var, 2); + $names = explode('.', $var, 3); $var = $names[0]; } if (!isset($_this->{$var})) { return null; } - - if (!empty($names[1])) { - return Set::extract($_this->{$var}, $names[1]); + if (!isset($names[1])) { + return $_this->{$var}; } - - return $_this->{$var}; + switch (count($names)) { + case 2: + if (isset($_this->{$var}[$names[1]])) { + return $_this->{$var}[$names[1]]; + } + break; + case 3: + if (isset($_this->{$var}[$names[1]][$names[2]])) { + return $_this->{$var}[$names[1]][$names[2]]; + } + if (!isset($_this->{$var}[$names[1]])) { + return null; + } + return Set::classicExtract($_this->{$var}[$names[1]], $names[2]); + break; + } + return null; } /**