Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization: Coalesce nil checks #132

Closed
iccir opened this issue Aug 8, 2018 · 1 comment
Closed

Optimization: Coalesce nil checks #132

iccir opened this issue Aug 8, 2018 · 1 comment

Comments

@iccir
Copy link
Member

iccir commented Aug 8, 2018

From the following code:

let foo = [[Foo alloc] init];

[foo bar];
[foo baz];

oj generates:

var $oj_t_0;let foo = (($oj_t_0 = (new $oj_oj._cls.$oj_c_Foo())) && $oj_t_0.init());

(foo && foo.$oj_f_bar());
(foo && foo.$oj_f_baz());

It should be possible to write a Babel transformer to remove the unneeded foo && … check:

var $oj_t_0;let foo = (($oj_t_0 = (new $oj_oj._cls.$oj_c_Foo())) && $oj_t_0.init());

(foo && (
    foo.$oj_f_bar(),
    foo.$oj_f_baz()
));

Care must be given that foo isn't closed over and modified by foo.$oj_f_bar or foo.$oj_f_baz. (This should never be the case for oj methods, but may be the case for other JavaScript).

@iccir
Copy link
Member Author

iccir commented Mar 16, 2023

This is no longer application due to #168.

The above code now turns into:

let foo = (new N$$_._c.N$_c_Foo()).init();

foo?.bar();
foo?.baz();

@iccir iccir closed this as completed Mar 16, 2023
@iccir iccir reopened this Mar 16, 2023
@iccir iccir closed this as not planned Won't fix, can't repro, duplicate, stale Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant