Skip to content

Commit

Permalink
Use array_fill for php
Browse files Browse the repository at this point in the history
  • Loading branch information
RblSb committed Mar 1, 2023
1 parent 8f3a88a commit 2832d33
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions std/php/_std/haxe/ds/Vector.hx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ private class PhpVectorData<T> {
public var length:Int;
public var data:NativeIndexedArray<T>;

public inline function new(length:Int) {
public inline function new(length:Int, data:NativeIndexedArray<T>) {
this.length = length;
data = new NativeIndexedArray();
this.data = data;
}
}

Expand All @@ -41,13 +41,11 @@ abstract Vector<T>(VectorData<T>) {
public var length(get, never):Int;

public inline function new(length:Int) {
this = new VectorData(length);
this = new VectorData(length, new NativeIndexedArray());
}

public static inline function createFilled<T>(length:Int, defaultValue:T):Vector<T> {
final vector = new Vector(length);
vector.fill(defaultValue);
return vector;
return cast new VectorData(length, Global.array_fill(0, length, defaultValue));
}

@:op([]) public inline function get(index:Int):T {
Expand All @@ -63,7 +61,7 @@ abstract Vector<T>(VectorData<T>) {
}

public inline function fill(value:T):Void
for (i in 0...length) this.data[i] = value;
this.data = Global.array_fill(0, length, value);

public static function blit<T>(src:Vector<T>, srcPos:Int, dest:Vector<T>, destPos:Int, len:Int):Void {
if (src == dest) {
Expand Down Expand Up @@ -109,8 +107,7 @@ abstract Vector<T>(VectorData<T>) {
}

static public inline function fromArrayCopy<T>(array:Array<T>):Vector<T> {
var vectorData = new VectorData(array.length);
vectorData.data = @:privateAccess array.arr;
var vectorData = new VectorData(array.length, @:privateAccess array.arr);
return cast vectorData;
}

Expand Down

0 comments on commit 2832d33

Please sign in to comment.