فهرست منبع

optimized iteration

ncannasse 12 سال پیش
والد
کامیت
291c5b48dd
3فایلهای تغییر یافته به همراه25 افزوده شده و 7 حذف شده
  1. 3 3
      h2d/Sprite.hx
  2. 4 4
      h3d/scene/Object.hx
  3. 18 0
      hxd/impl/ArrayIterator.hx

+ 3 - 3
h2d/Sprite.hx

@@ -274,16 +274,16 @@ class Sprite {
 		scaleY = v;
 	}
 
-	public function getChildAt( n ) {
+	public inline function getChildAt( n ) {
 		return childs[n];
 	}
 	
-	function get_numChildren() {
+	inline function get_numChildren() {
 		return childs.length;
 	}
 
 	public inline function iterator() {
-		return childs.iterator();
+		return new hxd.impl.ArrayIterator(childs);
 	}
 
 }

+ 4 - 4
h3d/scene/Object.hx

@@ -378,16 +378,16 @@ class Object {
 		return Type.getClassName(Type.getClass(this)).split(".").pop() + (name == null ? "" : "(" + name + ")");
 	}
 	
-	public function getChildAt( n ) {
+	public inline function getChildAt( n ) {
 		return childs[n];
 	}
 	
-	function get_numChildren() {
+	inline function get_numChildren() {
 		return childs.length;
 	}
 	
-	public inline function iterator() {
-		return childs.iterator();
+	public inline function iterator() : hxd.impl.ArrayIterator<Object> {
+		return new hxd.impl.ArrayIterator(childs);
 	}
 	
 	public function dispose() {

+ 18 - 0
hxd/impl/ArrayIterator.hx

@@ -0,0 +1,18 @@
+package hxd.impl;
+
+class ArrayIterator<T> {
+	var i : Int;
+	var l : Int;
+	var a : Array<T>;
+	public inline function new(a) {
+		this.i = 0;
+		this.a = a;
+		this.l = this.a.length;
+	}
+	public inline function hasNext() {
+		return i < l;
+	}
+	public inline function next() {
+		return a[i++];
+	}
+}