|
@@ -3,16 +3,17 @@ package haxe;
|
|
import haxe.iterators.RestIterator;
|
|
import haxe.iterators.RestIterator;
|
|
import haxe.iterators.RestKeyValueIterator;
|
|
import haxe.iterators.RestKeyValueIterator;
|
|
import java.NativeArray;
|
|
import java.NativeArray;
|
|
-import java.lang.System;
|
|
|
|
|
|
+import java.StdTypes;
|
|
import java.lang.Object;
|
|
import java.lang.Object;
|
|
|
|
+import java.lang.System;
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
-import java.StdTypes;
|
|
|
|
|
|
|
|
private typedef NativeRest<T> = NativeArray<T>;
|
|
private typedef NativeRest<T> = NativeArray<T>;
|
|
|
|
|
|
@:coreApi
|
|
@:coreApi
|
|
abstract Rest<T>(NativeRest<T>) {
|
|
abstract Rest<T>(NativeRest<T>) {
|
|
- public var length(get,never):Int;
|
|
|
|
|
|
+ public var length(get, never):Int;
|
|
|
|
+
|
|
inline function get_length():Int
|
|
inline function get_length():Int
|
|
return this.length;
|
|
return this.length;
|
|
|
|
|
|
@@ -24,7 +25,7 @@ abstract Rest<T>(NativeRest<T>) {
|
|
@:from extern inline static public function of<T>(array:Array<T>):Rest<T> {
|
|
@:from extern inline static public function of<T>(array:Array<T>):Rest<T> {
|
|
var result = createNative(array.length);
|
|
var result = createNative(array.length);
|
|
var src:NativeArray<Object> = cast @:privateAccess array.__a;
|
|
var src:NativeArray<Object> = cast @:privateAccess array.__a;
|
|
- for(i in 0...src.length)
|
|
|
|
|
|
+ for (i in 0...result.length)
|
|
result[i] = cast src[i];
|
|
result[i] = cast src[i];
|
|
return new Rest(result);
|
|
return new Rest(result);
|
|
}
|
|
}
|
|
@@ -32,8 +33,8 @@ abstract Rest<T>(NativeRest<T>) {
|
|
|
|
|
|
@:noDoc
|
|
@:noDoc
|
|
@:generic
|
|
@:generic
|
|
- static function ofNativePrimitive<TBoxed,TRest>(result:NativeRest<TBoxed>, collection:NativeArray<TRest>):Rest<TRest> {
|
|
|
|
- for(i in 0...collection.length)
|
|
|
|
|
|
+ static function ofNativePrimitive<TBoxed, TRest>(result:NativeRest<TBoxed>, collection:NativeArray<TRest>):Rest<TRest> {
|
|
|
|
+ for (i in 0...collection.length)
|
|
result[i] = cast collection[i];
|
|
result[i] = cast collection[i];
|
|
return new Rest(cast result);
|
|
return new Rest(cast result);
|
|
}
|
|
}
|
|
@@ -88,7 +89,7 @@ abstract Rest<T>(NativeRest<T>) {
|
|
return this[index];
|
|
return this[index];
|
|
|
|
|
|
@:to public function toArray():Array<T> {
|
|
@:to public function toArray():Array<T> {
|
|
- return [for(i in 0...this.length) this[i]];
|
|
|
|
|
|
+ return [for (i in 0...this.length) this[i]];
|
|
}
|
|
}
|
|
|
|
|
|
public inline function iterator():RestIterator<T>
|
|
public inline function iterator():RestIterator<T>
|
|
@@ -100,6 +101,7 @@ abstract Rest<T>(NativeRest<T>) {
|
|
extern inline public function append(item:T):Rest<T> {
|
|
extern inline public function append(item:T):Rest<T> {
|
|
return _append(createNative(this.length + 1), item);
|
|
return _append(createNative(this.length + 1), item);
|
|
}
|
|
}
|
|
|
|
+
|
|
function _append(result:NativeRest<T>, item:T):Rest<T> {
|
|
function _append(result:NativeRest<T>, item:T):Rest<T> {
|
|
System.arraycopy(this, 0, result, 0, this.length);
|
|
System.arraycopy(this, 0, result, 0, this.length);
|
|
result[this.length] = cast item;
|
|
result[this.length] = cast item;
|
|
@@ -109,6 +111,7 @@ abstract Rest<T>(NativeRest<T>) {
|
|
extern inline public function prepend(item:T):Rest<T> {
|
|
extern inline public function prepend(item:T):Rest<T> {
|
|
return _prepend(createNative(this.length + 1), item);
|
|
return _prepend(createNative(this.length + 1), item);
|
|
}
|
|
}
|
|
|
|
+
|
|
function _prepend(result:NativeRest<T>, item:T):Rest<T> {
|
|
function _prepend(result:NativeRest<T>, item:T):Rest<T> {
|
|
System.arraycopy(this, 0, result, 1, this.length);
|
|
System.arraycopy(this, 0, result, 1, this.length);
|
|
result[0] = cast item;
|
|
result[0] = cast item;
|
|
@@ -118,4 +121,4 @@ abstract Rest<T>(NativeRest<T>) {
|
|
public function toString():String {
|
|
public function toString():String {
|
|
return toArray().toString();
|
|
return toArray().toString();
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+}
|