HaxeFoundation / HaxeFoundation/haxe

could we optimize this?

Open
#10,185 2 comments 0 reactions 0 assignees View on GitHub
enhancement feature-analyzer
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

```haxe
class MapIterator {
final i:Iterator;
final f:T->S;

public inline function new(i:Iterator, f:T->S) {
this.i = i;
this.f = f;
}

public inline function hasNext():Bool {
return i.hasNext();
}

public inline function next():S {
return f(i.next());
}
}

function main() {
var a = [1,2,3];
for (s in new MapIterator(a.iterator(), i -> i * 2)) {
trace(s);
}
}
```

Currently generates:
```js
function Main_main() {
let a = [1,2,3];
let _g_i_current = 0;
let _g_f = function(i) {
return i * 2;
};
while(_g_i_current < a.length) console.log("src/Main.hx:22:",_g_f(a[_g_i_current++]));
}
```

I wonder if we could safely inline `_g_f` call like we do for immedately-invoked local functions?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.