|
@@ -7,7 +7,7 @@ import java.lang.System;
|
|
|
import java.lang.Object;
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
-private typedef NativeRest<T> = NativeArray<Object>;
|
|
|
+private typedef NativeRest<T> = NativeArray<T>;
|
|
|
|
|
|
@:coreApi
|
|
|
abstract Rest<T>(NativeRest<T>) {
|
|
@@ -15,27 +15,34 @@ abstract Rest<T>(NativeRest<T>) {
|
|
|
inline function get_length():Int
|
|
|
return this.length;
|
|
|
|
|
|
+ #if jvm
|
|
|
@:from static public function of<T>(array:Array<T>):Rest<T> {
|
|
|
- var native = @:privateAccess array.__a;
|
|
|
- var result:NativeRest<T>;
|
|
|
- #if jvm
|
|
|
- result = (cast native:Object).clone();
|
|
|
- #else
|
|
|
- result = new NativeRest<T>(native.length);
|
|
|
- for(i in 0...native.length)
|
|
|
- result[i] = cast native[i];
|
|
|
- #end
|
|
|
+ return new Rest(@:privateAccess array.__a);
|
|
|
+ }
|
|
|
+ #else
|
|
|
+ @:from extern inline static public function of<T>(array:Array<T>):Rest<T> {
|
|
|
+ var result = createNative(array.length);
|
|
|
+ var src:NativeArray<Object> = cast @:privateAccess array.__a;
|
|
|
+ for(i in 0...src.length)
|
|
|
+ result[i] = cast src[i];
|
|
|
return new Rest(result);
|
|
|
}
|
|
|
+ #end
|
|
|
|
|
|
inline function new(a:NativeRest<T>):Void
|
|
|
this = a;
|
|
|
|
|
|
+ /**
|
|
|
+ * Implemented in genjvm (to auto-box primitive types) and genjava
|
|
|
+ */
|
|
|
+ static function createNative<T>(length:Int):NativeRest<T>
|
|
|
+ return new NativeRest<T>(length);
|
|
|
+
|
|
|
@:arrayAccess inline function get(index:Int):T
|
|
|
- return cast this[index];
|
|
|
+ return this[index];
|
|
|
|
|
|
@:to public function toArray():Array<T> {
|
|
|
- return [for(i in 0...this.length) cast this[i]];
|
|
|
+ return [for(i in 0...this.length) this[i]];
|
|
|
}
|
|
|
|
|
|
public inline function iterator():RestIterator<T>
|
|
@@ -44,15 +51,19 @@ abstract Rest<T>(NativeRest<T>) {
|
|
|
public inline function keyValueIterator():RestKeyValueIterator<T>
|
|
|
return new RestKeyValueIterator<T>(this);
|
|
|
|
|
|
- public function append(item:T):Rest<T> {
|
|
|
- var result = new NativeRest<T>(this.length + 1);
|
|
|
+ extern inline public function append(item:T):Rest<T> {
|
|
|
+ return _append(createNative(this.length + 1), item);
|
|
|
+ }
|
|
|
+ function _append(result:NativeRest<T>, item:T):Rest<T> {
|
|
|
System.arraycopy(this, 0, result, 0, this.length);
|
|
|
result[this.length] = cast item;
|
|
|
return new Rest(result);
|
|
|
}
|
|
|
|
|
|
- public function prepend(item:T):Rest<T> {
|
|
|
- var result = new NativeRest<T>(this.length + 1);
|
|
|
+ extern inline public function prepend(item:T):Rest<T> {
|
|
|
+ return _prepend(createNative(this.length + 1), item);
|
|
|
+ }
|
|
|
+ function _prepend(result:NativeRest<T>, item:T):Rest<T> {
|
|
|
System.arraycopy(this, 0, result, 1, this.length);
|
|
|
result[0] = cast item;
|
|
|
return new Rest(result);
|