mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-17 08:51:34 +00:00
Add Array#concat and add a return type for Array#push (#214)
This commit is contained in:
@ -181,6 +181,25 @@ export class Array<T> {
|
||||
return newLength;
|
||||
}
|
||||
|
||||
concat(items: Array<T>): Array<T> {
|
||||
var thisLen: isize = this.length_;
|
||||
var otherLen = (items == null) ? 0 : items.length_;
|
||||
var outLen = thisLen + otherLen;
|
||||
var out: Array<T> = new Array<T>(outLen);
|
||||
|
||||
if (thisLen) {
|
||||
memory.copy(changetype<usize>(out.buffer_) + HEADER_SIZE,
|
||||
changetype<usize>(this.buffer_) + HEADER_SIZE,
|
||||
<usize>(thisLen << alignof<T>()));
|
||||
}
|
||||
if (otherLen) {
|
||||
memory.copy(changetype<usize>(out.buffer_) + HEADER_SIZE + <usize>(thisLen << alignof<T>()),
|
||||
changetype<usize>(items.buffer_) + HEADER_SIZE,
|
||||
<usize>(otherLen << alignof<T>()));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
pop(): T {
|
||||
var length = this.length_;
|
||||
if (length < 1) throw new RangeError("Array is empty");
|
||||
|
Reference in New Issue
Block a user