mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-16 08:21:44 +00:00
give it a shot
This commit is contained in:
@ -34,6 +34,22 @@ export class Array<T> extends ArrayBufferView {
|
||||
|
||||
constructor(length: i32 = 0) {
|
||||
super(length, alignof<T>());
|
||||
if (isReference<T>()) {
|
||||
if (!isNullable<T>()) {
|
||||
let cur = this.dataStart;
|
||||
let end = cur + (<usize>length << alignof<T>());
|
||||
while (cur < end) {
|
||||
// TODO: probably a common reason for complaints of T not having a default ctor. what if
|
||||
// the array ctor would also take default arguments, like `new Array<Ref>(10, ...args)`?
|
||||
store<T>(cur,
|
||||
isString<T>()
|
||||
? "" // no need to instantiate
|
||||
: RETAIN<T,this>(instantiate<T>(), this)
|
||||
);
|
||||
cur += sizeof<T>();
|
||||
}
|
||||
}
|
||||
}
|
||||
this.length_ = length;
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ import { HEAP_BASE, memory } from "./memory";
|
||||
// Changes the size of a previously allocated, but not yet registered, runtime object, for
|
||||
// example when a pre-allocated buffer turned out to be too small or too large. This works by
|
||||
// aligning dynamic allocations to actual block size internally so in the best case REALLOCATE
|
||||
// only updates payload size while in the worst case moves the object to larger a block.
|
||||
// only updates payload size while in the worst case moves the object to a larger block.
|
||||
//
|
||||
// DISCARD(ref)
|
||||
// ------------
|
||||
|
Reference in New Issue
Block a user