@@ -2,56 +2,56 @@ import { globalVariable } from "./find-global.js";
22import { ref } from "./types.js" ;
33
44export class JSObjectSpace {
5- private _valueMap : Map < any , number > ;
5+ private _valueRefMap : Map < any , number > ;
66 private _values : ( any | undefined ) [ ] ;
7- private _rcById : number [ ] ;
8- private _freeStack : number [ ] ;
7+ private _refCounts : number [ ] ;
8+ private _freeSlotStack : number [ ] ;
99
1010 constructor ( ) {
1111 this . _values = [ ] ;
1212 this . _values [ 0 ] = undefined ;
1313 this . _values [ 1 ] = globalVariable ;
1414
15- this . _valueMap = new Map ( ) ;
16- this . _valueMap . set ( globalVariable , 1 ) ;
15+ this . _valueRefMap = new Map ( ) ;
16+ this . _valueRefMap . set ( globalVariable , 1 ) ;
1717
18- this . _rcById = [ ] ;
19- this . _rcById [ 0 ] = 0 ;
20- this . _rcById [ 1 ] = 1 ;
18+ this . _refCounts = [ ] ;
19+ this . _refCounts [ 0 ] = 0 ;
20+ this . _refCounts [ 1 ] = 1 ;
2121
22- this . _freeStack = [ ] ;
22+ this . _freeSlotStack = [ ] ;
2323 }
2424
2525 retain ( value : any ) {
26- const id = this . _valueMap . get ( value ) ;
26+ const id = this . _valueRefMap . get ( value ) ;
2727 if ( id !== undefined ) {
28- this . _rcById [ id ] ++ ;
28+ this . _refCounts [ id ] ++ ;
2929 return id ;
3030 }
3131
32- const newId = this . _freeStack . length > 0 ? this . _freeStack . pop ( ) ! : this . _values . length ;
32+ const newId = this . _freeSlotStack . length > 0 ? this . _freeSlotStack . pop ( ) ! : this . _values . length ;
3333 this . _values [ newId ] = value ;
34- this . _rcById [ newId ] = 1 ;
35- this . _valueMap . set ( value , newId ) ;
34+ this . _refCounts [ newId ] = 1 ;
35+ this . _valueRefMap . set ( value , newId ) ;
3636 return newId ;
3737 }
3838
3939 retainByRef ( ref : ref ) {
40- this . _rcById [ ref ] ++ ;
40+ this . _refCounts [ ref ] ++ ;
4141 return ref ;
4242 }
4343
4444 release ( ref : ref ) {
45- if ( -- this . _rcById [ ref ] !== 0 ) return ;
45+ if ( -- this . _refCounts [ ref ] !== 0 ) return ;
4646
4747 const value = this . _values [ ref ] ;
48- this . _valueMap . delete ( value ) ;
48+ this . _valueRefMap . delete ( value ) ;
4949 if ( ref === this . _values . length - 1 ) {
5050 this . _values . length = ref ;
51- this . _rcById . length = ref ;
51+ this . _refCounts . length = ref ;
5252 } else {
5353 this . _values [ ref ] = undefined ;
54- this . _freeStack . push ( ref ) ;
54+ this . _freeSlotStack . push ( ref ) ;
5555 }
5656 }
5757
0 commit comments