ソースを参照

[lua] revert back to old array.unshift behavior

Justin Donaldson 8 年 前
コミット
11c62fe1fb
1 ファイル変更3 行追加9 行削除
  1. 3 9
      std/lua/_std/Array.hx

+ 3 - 9
std/lua/_std/Array.hx

@@ -135,15 +135,9 @@ class Array<T> {
 	}
 
 	public function unshift( x : T ) : Void {
-		if (this.length == 0) {
-			this[0] = x;
-			return;
-		}
-		lua.Table.insert(untyped this, 1, x);
-		var tmp = this[0];
-		this[0] = this[1];
-		this[1] = tmp;
-		length++;
+		var len = length;
+		for (i in 0...len) this[len - i] = this[len - i - 1];
+		this[0] = x;
 	}
 
 	public inline function insert( pos : Int, x : T ) : Void {