mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-15 16:01:30 +00:00
Initial GC integration (#196)
This commit is contained in:
@ -104,6 +104,7 @@ export class Set<K> {
|
||||
let bucketPtrBase = changetype<usize>(this.buckets) + <usize>(hashCode & this.bucketsMask) * BUCKET_SIZE;
|
||||
entry.taggedNext = load<usize>(bucketPtrBase, HEADER_SIZE_AB);
|
||||
store<usize>(bucketPtrBase, changetype<usize>(entry), HEADER_SIZE_AB);
|
||||
if (isManaged<K>()) __gc_link(changetype<usize>(this), changetype<usize>(key)); // tslint:disable-line
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,4 +152,19 @@ export class Set<K> {
|
||||
this.entriesCapacity = newEntriesCapacity;
|
||||
this.entriesOffset = this.entriesCount;
|
||||
}
|
||||
|
||||
private __gc(): void {
|
||||
if (isManaged<K>()) {
|
||||
let entries = this.entries;
|
||||
let offset: usize = 0;
|
||||
let end: usize = this.entriesOffset * ENTRY_SIZE<K>();
|
||||
while (offset < end) {
|
||||
let entry = changetype<SetEntry<K>>(
|
||||
changetype<usize>(entries) + HEADER_SIZE_AB + offset * ENTRY_SIZE<K>()
|
||||
);
|
||||
if (!(entry.taggedNext & EMPTY)) __gc_mark(changetype<usize>(entry.key)); // tslint:disable-line
|
||||
offset += ENTRY_SIZE<K>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user