File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,28 +9,30 @@ type RawParser<T> = (input: number) => ParserResult<T>;
99type Cache < T > = Map < number , MemoizationCacheResult < ParserResult < T > > > ;
1010
1111let currentSource = "" ;
12- const allCache : Set < WeakRef < Cache < unknown > > > = new Set ( ) ;
12+ const allCache : Array < WeakRef < Cache < unknown > > > = [ ] ;
1313
1414const rawParser = Symbol ( "rawParser" ) ;
1515
1616export 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 ) ;
You can’t perform that action at this time.
0 commit comments