Ver Fonte

added haxe.ds.Vector.blit (fixed issue #1018)

Simon Krajewski há 12 anos atrás
pai
commit
96f41801eb
2 ficheiros alterados com 10 adições e 108 exclusões
  1. 7 74
      std/haxe/ds/Vector.hx
  2. 3 34
      tests/unit/unitstd/haxe/ds/Vector.unit.hx

+ 7 - 74
std/haxe/ds/Vector.hx

@@ -91,38 +91,6 @@ abstract Vector<T>(VectorData<T>) {
 		return this[index] = val;
 	}
 
-	/**
-		Returns the value at index [index].
-
-		WARNING: On some platforms it may not perform any bounds check,
-		so accessing it out-of-bounds may cause an irrecoverable crash
-		or data corruption
-	**
-	public inline function unsafeGet(index:Int):T
-	{
-		#if cpp
-			return untyped this.__unsafeGet(index);
-		#else
-			return this[index];
-		#end
-	}*/
-
-	/**
-		Sets the value at index [index] to [val]
-
-		WARNING: On some platforms it may not perform any bounds check,
-		so accessing it out-of-bounds may cause an irrecoverable crash
-		or data corruption
-	**
-	public inline function unsafeSet(index:Int, val:T):Void
-	{
-		#if cpp
-			untyped this.__unsafeSet(index, val);
-		#else
-			this[index] = val;
-		#end
-	}*/
-
 	/**
 		Returns the length of [this] Vector.
 	**/
@@ -144,57 +112,22 @@ abstract Vector<T>(VectorData<T>) {
 		Copies [length] of elements from [src] Vector, beginning at [srcPos] to [dest] Vector, beginning at [destPos]
 
 		The results are unspecified if [length] results in out-of-bounds access, or if [src] or [dest] are null
-	**
-	public static #if (cs || java || neko) inline #end function blit<T>(src:Vector<T>, srcPos:Int, dest:Vector<T>, destPos:Int, length:Int):Void
+	**/
+	public #if (cs || java || neko) inline #end function blit<T>(srcPos:Int, dest:Vector<T>, destPos:Int, length:Int):Void
 	{
 		#if neko
-			untyped __dollar__ablit(dst,dstPos,src,srcPos,length);
+			untyped __dollar__ablit(dest,destPos,this,srcPos,length);
 		#elseif java
-			java.lang.System.arraycopy(src, srcPos, dest, destPos, length);
+			java.lang.System.arraycopy(this, srcPos, dest, destPos, length);
 		#elseif cs
-			cs.system.Array.Copy(cast src, srcPos,cast dest, destPos, length);
+			cs.system.Array.Copy(cast this, srcPos,cast dest, destPos, length);
 		#else
 			for (i in 0...length)
 			{
-				dest[destPos + i] = src[srcPos + i];
-			}
-		#end
-	}*/
-
-	/**
-		Returns a Vector with the same elements as [this], and with size [targetSize].
-
-		WARNING: On some platforms, this function may modify [this] Vector, while on others it may return a copy
-	**
-	public #if (java || cs) inline #end function grow(targetSize:Int):Vector<T>
-	{
-		#if (neko || java || cs)
-			//because of type parameters' erasure, java must run this inlined
-			var len = #if cs this.Length #else this.length #end;
-			var ret = new Vector(targetSize), targetIdx = (len < targetSize) ? len : targetSize;
-			blit(cast this, 0, ret, 0, targetIdx);
-			return ret;
-		#elseif js
-			untyped this.length = targetSize;
-			return cast this;
-		#elseif flash
-			this.fixed = false;
-			this.length = targetSize;
-			this.fixed = true;
-			return cast this;
-		#elseif cpp
-			untyped this.__SetSize(targetSize);
-			return cast this;
-		#else
-			var len = this.length;
-			while (len > targetSize)
-			{
-				this.pop();
+				dest[destPos + i] = this[srcPos + i];
 			}
-			untyped this.length = targetSize;
-			return cast this;
 		#end
-	}*/
+	}
 
 	/**
 		Extracts the data of [this] Vector.

+ 3 - 34
tests/unit/unitstd/haxe/ds/Vector.unit.hx

@@ -61,42 +61,25 @@ vec2[1] == "4";
 vec2[0] += "a";
 vec2[0] = "1a";
 
-/*
-// grow
-vec2 = vec2.grow(15);
-vec2.length == 15;
-(vec2[3] = "4") == "4";
-(vec2[4] = "5") == "5";
-vec2[0] == "1a";
-vec2[3] == "4";
-vec2[4] == "5";
-(vec2[10] = "11") == "11";
-vec2[10] == "11";
-
-vec2 = vec2.grow(2);
-vec2.length == 2;
-vec2[0] == "1a";
-vec2[1] == "4";
-
 // blit
 var vec3 = haxe.ds.Vector.fromArrayCopy([0,1,2,3,4,5,6]);
 var vec4 = new haxe.ds.Vector(5);
 
-haxe.ds.Vector.blit(vec3, 0, vec4, 1, 3);
+vec3.blit(0, vec4, 1, 3);
 vec4[1] == 0;
 vec4[2] == 1;
 vec4[3] == 2;
 vec4[4] == vNullInt;
 vec4[0] == vNullInt;
 
-haxe.ds.Vector.blit(vec3, 0, vec4, 0, 5);
+vec3.blit(0, vec4, 0, 5);
 vec4[0] == 0;
 vec4[1] == 1;
 vec4[2] == 2;
 vec4[3] == 3;
 vec4[4] == 4;
 
-haxe.ds.Vector.blit(vec4, 1, vec3, 0, 4);
+vec4.blit(1, vec3, 0, 4);
 //vec3 should be [1,2,3,4,4,5,6]
 vec3[0] == 1;
 vec3[1] == 2;
@@ -105,17 +88,3 @@ vec3[3] == 4;
 vec3[4] == 4;
 vec3[5] == 5;
 vec3[6] == 6;
-
-// unsafe get / set
-vec3.unsafeGet(0) == 1;
-vec3.unsafeGet(1) == 2;
-vec3.unsafeGet(2) == 3;
-vec3.unsafeGet(3) == 4;
-
-vec3.unsafeSet(0, 10);
-vec3[0] == 10;
-vec3.unsafeGet(0) == 10;
-vec3.unsafeGet(6) == 6;
-vec3.unsafeSet(6, 10);
-vec3.unsafeGet(6) == 10;
-*/