xp-framework / compiler

Compiles future PHP to today's PHP.
19 stars 0 forks source link

Inline nullable checks when casting #131

Closed thekid closed 2 years ago

thekid commented 2 years ago

This pull request generates more efficient code when performing casting to nullable types:

// Input
$value= (?string)$request->param('input');

// Generated code, before
$value= cast($request->param('input'), 'string', false);

// Generated code, now
$value= null === ($t0= $request->param('input')) ? null : (string)$t0;

In these cases, we can also do without the cast() function from XP Core.

thekid commented 2 years ago

Released in https://github.com/xp-framework/compiler/releases/tag/v8.1.0