Skip to content

Commit 605acd8

Browse files
committed
use a much more reliable array
1 parent 271b6e8 commit 605acd8

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/parser/parser_lib.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,30 @@ type RawParser<T> = (input: number) => ParserResult<T>;
99
type Cache<T> = Map<number, MemoizationCacheResult<ParserResult<T>>>;
1010

1111
let currentSource = "";
12-
const allCache: Set<WeakRef<Cache<unknown>>> = new Set();
12+
const allCache: Array<WeakRef<Cache<unknown>>> = [];
1313

1414
const rawParser = Symbol("rawParser");
1515

1616
export class Parser<T> {
1717
readonly [rawParser]: RawParser<T>;
1818
constructor(parser: RawParser<T>) {
1919
const cache: Cache<T> = new Map();
20-
allCache.add(new WeakRef(cache));
20+
allCache.push(new WeakRef(cache));
2121
this[rawParser] = memoize<RawParser<T>, number, Cache<T>>(
2222
parser,
2323
{ cache },
2424
);
2525
}
2626
parse(source: string): IterableResult<T> {
2727
currentSource = source;
28-
for (const memo of allCache) {
29-
const ref = memo.deref();
28+
let i = 0;
29+
while (i < allCache.length) {
30+
const ref = allCache[i].deref();
3031
if (ref == null) {
31-
allCache.delete(memo);
32+
allCache.splice(i, 1);
3233
} else {
3334
ref.clear();
35+
i++;
3436
}
3537
}
3638
return this[rawParser](0).map(({ value }) => value);

0 commit comments

Comments
 (0)