mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-14 23:41:30 +00:00
Initial GC integration (#196)
This commit is contained in:
@ -114,6 +114,8 @@ export class Map<K,V> {
|
||||
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
|
||||
if (isManaged<V>()) __gc_link(changetype<usize>(this), changetype<usize>(value)); // tslint:disable-line
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,4 +164,22 @@ export class Map<K,V> {
|
||||
this.entriesCapacity = newEntriesCapacity;
|
||||
this.entriesOffset = this.entriesCount;
|
||||
}
|
||||
|
||||
private __gc(): void {
|
||||
if (isManaged<K>() || isManaged<V>()) {
|
||||
let entries = this.entries;
|
||||
let offset: usize = 0;
|
||||
let end: usize = this.entriesOffset * ENTRY_SIZE<K,V>();
|
||||
while (offset < end) {
|
||||
let entry = changetype<MapEntry<K,V>>(
|
||||
changetype<usize>(entries) + HEADER_SIZE_AB + offset * ENTRY_SIZE<K,V>()
|
||||
);
|
||||
if (!(entry.taggedNext & EMPTY)) {
|
||||
if (isManaged<K>()) __gc_mark(changetype<usize>(entry.key)); // tslint:disable-line
|
||||
if (isManaged<V>()) __gc_mark(changetype<usize>(entry.value)); // tslint:disable-line
|
||||
}
|
||||
offset += ENTRY_SIZE<K,V>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user