forked from LeenkxTeam/LNXSDK
Update
This commit is contained in:
@ -41,7 +41,7 @@ private typedef VectorData<T> =
|
||||
eval.Vector<T>
|
||||
#else
|
||||
Array<T>
|
||||
#end
|
||||
#end;
|
||||
|
||||
/**
|
||||
A Vector is a storage of fixed size. It can be faster than Array on some
|
||||
@ -61,7 +61,7 @@ abstract Vector<T>(VectorData<T>) {
|
||||
|
||||
If `length` is less than or equal to 0, the result is unspecified.
|
||||
**/
|
||||
public inline function new(length:Int) {
|
||||
extern overload public inline function new(length:Int) {
|
||||
#if flash10
|
||||
this = new flash.Vector<T>(length, true);
|
||||
#elseif neko
|
||||
@ -75,7 +75,7 @@ abstract Vector<T>(VectorData<T>) {
|
||||
#elseif cpp
|
||||
this = NativeArray.create(length);
|
||||
#elseif python
|
||||
this = python.Syntax.code("[{0}]*{1}", null, length);
|
||||
this = python.Syntax.code("([{0}]*{1})", null, length);
|
||||
#elseif lua
|
||||
this = untyped __lua_table__({length: length});
|
||||
#elseif eval
|
||||
@ -86,6 +86,43 @@ abstract Vector<T>(VectorData<T>) {
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a new Vector of length `length` filled with `defaultValue` elements.
|
||||
|
||||
Can be faster than `new Vector(length)` for iteration on some targets for non-nullable elements.
|
||||
|
||||
If `length` is less than or equal to 0, the result is unspecified.
|
||||
**/
|
||||
extern overload public inline function new(length:Int, defaultValue:T):Vector<T> {
|
||||
#if js
|
||||
this = [for (_ in 0...length) defaultValue];
|
||||
#elseif python
|
||||
this = python.Syntax.code("([{0}]*{1})", defaultValue, length);
|
||||
#else
|
||||
|
||||
#if flash10
|
||||
this = new flash.Vector<T>(length, true);
|
||||
#elseif neko
|
||||
this = untyped __dollar__amake(length);
|
||||
#elseif cs
|
||||
this = new cs.NativeArray(length);
|
||||
#elseif java
|
||||
this = new java.NativeArray(length);
|
||||
#elseif cpp
|
||||
this = NativeArray.create(length);
|
||||
#elseif lua
|
||||
this = untyped __lua_table__({length: length});
|
||||
#elseif eval
|
||||
this = new eval.Vector(length);
|
||||
#else
|
||||
this = [];
|
||||
untyped this.length = length;
|
||||
#end
|
||||
fill(defaultValue);
|
||||
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the value at index `index`.
|
||||
|
||||
@ -141,6 +178,12 @@ abstract Vector<T>(VectorData<T>) {
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Sets all `length` elements of `this` Vector to `value`.
|
||||
**/
|
||||
public inline function fill(value:T):Void
|
||||
for (i in 0...length) this[i] = value;
|
||||
|
||||
/**
|
||||
Copies `length` of elements from `src` Vector, beginning at `srcPos` to
|
||||
`dest` Vector, beginning at `destPos`
|
||||
|
||||
Reference in New Issue
Block a user