Permalink
Fetching contributors…
Cannot retrieve contributors at this time
executable file 57 lines (49 sloc) 2.1 KB
<?php
/*
+--------------------------------------------------------------------------+
| Zephir Language |
+--------------------------------------------------------------------------+
| Copyright (c) 2013-2016 Zephir Team and contributors |
+--------------------------------------------------------------------------+
| This source file is subject the MIT license, that is bundled with |
| this package in the file LICENSE, and is available through the |
| world-wide-web at the following url: |
| http://zephir-lang.com/license.html |
| |
| If you did not receive a copy of the MIT license and are unable |
| to obtain it through the world-wide-web, please send a note to |
| license@zephir-lang.com so we can mail you a copy immediately. |
+--------------------------------------------------------------------------+
*/
namespace Zephir\Optimizers\FunctionCall;
use Zephir\Call;
use Zephir\CompilationContext;
use Zephir\CompilerException;
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 (count($expression['parameters']) != 1) {
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);
}
}