Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
50 lines (41 sloc) 1.25 KB
<?php
/*
* This file is part of the Zephir.
*
* (c) Zephir Team <team@zephir-lang.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zephir\Optimizers\FunctionCall;
use Zephir\Call;
use Zephir\CompilationContext;
use Zephir\CompiledExpression;
use Zephir\Optimizers\OptimizerAbstract;
/**
* StrlenOptimizer.
*
* Optimizes calls to 'strlen' using internal function
*/
class StrlenOptimizer extends OptimizerAbstract
{
/**
* @param array $expression
* @param Call $call
* @param CompilationContext $context
*
* @return bool|CompiledExpression|mixed
*/
public function optimize(array $expression, Call $call, CompilationContext $context)
{
if (!isset($expression['parameters'])) {
return false;
}
if (1 != \count($expression['parameters'])) {
return false;
}
$context->headersManager->add('kernel/string');
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
return new CompiledExpression('int', 'zephir_fast_strlen_ev('.$resolvedParams[0].')', $expression);
}
}