<?php namespace lang\ast\syntax\php;
use lang\ast\nodes\Braced;
use lang\ast\syntax\Extension;
class Inline implements Extension {
private $inline= [];
public function setup($language, $emitter) {
$emitter->transform('method', function($codegen, $node) {
if ($node->annotation('Inline')) {
$this->inline[$node->name]= $node;
}
});
$emitter->transform('scope', function($codegen, $node) {
if ('self' === $node->type && $node->member->is('invoke')) {
if ($method= $this->inline[$node->member->expression->expression] ?? null) {
if ($statement= $method->body[0] ?? null && $statement instanceof ReturnNode) {
return new Braced($method->body[0]->expression);
}
}
}
});
}
}
Inlining a private method yields a performance difference of 1.560 seconds vs. 1.826 seconds for 10 million invocations, not sure about the real benefit here.
Proof of concept:
Inlining a private method yields a performance difference of 1.560 seconds vs. 1.826 seconds for 10 million invocations, not sure about the real benefit here.