Explorar o código

added haxe.ds.Vector toArray

Nicolas Cannasse %!s(int64=11) %!d(string=hai) anos
pai
achega
7c322429f8
Modificáronse 1 ficheiros con 15 adicións e 0 borrados
  1. 15 0
      std/haxe/ds/Vector.hx

+ 15 - 0
std/haxe/ds/Vector.hx

@@ -129,6 +129,21 @@ abstract Vector<T>(VectorData<T>) {
 		#end
 	}
 
+	/**
+		Creates a new Array, copy the content from the Vector to it, and returns it.
+	**/
+	public #if flash inline #end function toArray():Array<T> {
+		var a = new Array();
+		var len = length;
+		#if (cpp || neko)
+		// prealloc good size
+		if( len > 0 ) a[len - 1] = get(0);
+		#end
+		for( i in 0...len )
+			a[i] = get(i);
+		return a;
+	}
+		
 	/**
 		Extracts the data of `this` Vector.