Initial GC integration (#196)

This commit is contained in:
Daniel Wirtz
2018-08-02 18:23:02 +02:00
committed by GitHub
parent 671121bf70
commit dc0f271fc2
139 changed files with 7370 additions and 5016 deletions

View File

@ -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>();
}
}
}
}