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

[optimisation] For loop is not removed if variable is used #11691

Open
AxGord opened this issue Jun 8, 2024 · 0 comments
Open

[optimisation] For loop is not removed if variable is used #11691

AxGord opened this issue Jun 8, 2024 · 0 comments

Comments

@AxGord
Copy link

AxGord commented Jun 8, 2024

For loop is not removed if variable is used.
In cases where inline methods are used, an array is created in the same way, although it is possible without it.

var m:Float = 0;
for (e in [1, 2, 3]) m = Math.max(m, e);
trace(m);

Compiles to js:

let m = 0;
m = Math.max(m,1);
m = Math.max(m,2);
m = Math.max(m,3);
console.log("Test.hx:7:",m);

But

var m:Float = 0;
var a = [1, 2, 3];
for (e in a) m = Math.max(m, e);
trace(m);

Compiles to js:

let m1 = 0;
let a = [1,2,3];
let _g = 0;
while(_g < a.length) m1 = Math.max(m1,a[_g  ]);
console.log("Test.hx:12:",m1);
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