Skip to content

Instantly share code, notes, and snippets.

@fal-works
Created April 20, 2020 19:59
Show Gist options
  • Save fal-works/89c6c4faaee0871f04833b4c4a3b80ab to your computer and use it in GitHub Desktop.
Save fal-works/89c6c4faaee0871f04833b4c4a3b80ab to your computer and use it in GitHub Desktop.
Haxe: Cannot force Iterator to be inlined
abstract MyInt(Int) from Int to Int {
@:op(A...B) static extern inline function iter(a: MyInt, b: MyInt): MyIntIterator
return new MyIntIterator(a, b);
public extern inline function toInt()
return this;
}
// @:access(IntIterator)
// @:forward(min, max, hasNext)
// @:notNull
// abstract MyIntIterator(IntIterator) from IntIterator {
// public extern inline function next(): MyInt
// return this.next();
// }
class MyIntIterator {
var min:Int;
var max:Int;
// Adding "extern" gives error: "Extern constructor could not be inlined"
public inline function new(min:Int, max:Int) {
this.min = min;
this.max = max;
}
public inline function hasNext(): Bool
return min < max;
public inline function next(): MyInt
return min++;
}
class Main {
static function intIterator(count: Int) {
for (i in 0...count) {
final a = i;
};
}
static function myIntIterator(count: MyInt) {
for (i in (0: MyInt)...count) {
final a = i;
};
}
static function whileIteration(count: Int) {
var i = 0;
while (i < count) {
final a = i;
++i;
}
}
static function main() {
intIterator(10);
myIntIterator(10);
whileIteration(10);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment