File tree 1 file changed +20
-19
lines changed
1 file changed +20
-19
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
- // This is a free list to avoid creating so many of the same object.
4
- exports . FreeList = function ( name , max , constructor ) {
5
- this . name = name ;
6
- this . constructor = constructor ;
7
- this . max = max ;
8
- this . list = [ ] ;
9
- } ;
10
-
11
-
12
- exports . FreeList . prototype . alloc = function ( ) {
13
- return this . list . length ? this . list . pop ( ) :
14
- this . constructor . apply ( this , arguments ) ;
15
- } ;
3
+ class FreeList {
4
+ constructor ( name , max , ctor ) {
5
+ this . name = name ;
6
+ this . ctor = ctor ;
7
+ this . max = max ;
8
+ this . list = [ ] ;
9
+ }
16
10
11
+ alloc ( ) {
12
+ return this . list . length ? this . list . pop ( ) :
13
+ this . ctor . apply ( this , arguments ) ;
14
+ }
17
15
18
- exports . FreeList . prototype . free = function ( obj ) {
19
- if ( this . list . length < this . max ) {
20
- this . list . push ( obj ) ;
21
- return true ;
16
+ free ( obj ) {
17
+ if ( this . list . length < this . max ) {
18
+ this . list . push ( obj ) ;
19
+ return true ;
20
+ }
21
+ return false ;
22
22
}
23
- return false ;
24
- } ;
23
+ }
24
+
25
+ module . exports = { FreeList} ;
You can’t perform that action at this time.
0 commit comments