Commit 9e48c870 by Seldaek

* Performance improvements [removed isset calls when doing {$var} but not inside…

* Performance improvements [removed isset calls when doing {$var} but not inside other blocks/functions] git-svn-id: svn://dwoo.org/dwoo/trunk@18 0598d79b-80c4-4d41-97ba-ac86fbbd088b
parent 6b42834f
......@@ -1377,7 +1377,7 @@ class DwooCompiler implements DwooICompiler
}
else
{
$output = $this->parseVarKey($key);
$output = $this->parseVarKey($key, $curBlock);
}
if($hasMethodCall)
......@@ -1457,7 +1457,7 @@ class DwooCompiler implements DwooICompiler
* @param string $key the variable to parse
* @return string parsed variable
*/
protected function parseVarKey($key)
protected function parseVarKey($key, $curBlock)
{
if(preg_match('#dwoo\.(get|post|server|cookies|session|env|request)((?:\.[a-z0-9_-]+)+)#i', $key, $m))
{
......@@ -1467,6 +1467,9 @@ class DwooCompiler implements DwooICompiler
$key = '$_'.$global;
foreach(explode('.', ltrim($m[2], '.')) as $part)
$key .= '['.var_export($part, true).']';
if($curBlock === 'root')
$output = $key;
else
$output = '(isset('.$key.')?'.$key.':null)';
}
elseif(preg_match('#dwoo\.const\.([a-z0-9_:-]+)#i', $key, $m))
......@@ -1474,9 +1477,11 @@ class DwooCompiler implements DwooICompiler
if($this->securityPolicy !== null && $this->securityPolicy->getConstantHandling() === DwooSecurityPolicy::CONST_DISALLOW)
return 'null';
if(strpos($m[1], ':') !== false)
$output = '(defined("'.$m[1].'") ? constant("'.$m[1].'") : null)';
$output = 'constant("'.$m[1].'")';
else
$output = '(defined("'.$m[1].'") ? '.$m[1].' : null)';
$output = $m[1];
if($curBlock !== 'root')
$output = '(defined("'.$m[1].'") ? '.$output.' : null)';
}
elseif($this->scope !== null)
{
......@@ -1496,6 +1501,9 @@ class DwooCompiler implements DwooICompiler
}
else
{
if($curBlock === 'root')
$output = '$this->scope["'.$key.'"]';
else
$output = '(isset($this->scope["'.$key.'"]) ? $this->scope["'.$key.'"] : null)';
}
}
......@@ -1546,6 +1554,7 @@ class DwooCompiler implements DwooICompiler
array_shift($m[1]);
}
if($curBlock !== 'root')
$output = '(isset('.$output.') ? '.$output.':null)';
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment