Browse Source

added haxe.ds.Vector toArray

Nicolas Cannasse 11 years ago
parent
commit
7c322429f8
1 changed files with 15 additions and 0 deletions
  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.