Skip to content

Commit f04387e

Browse files
committed
lib: refactor internal/freelist
PR-URL: #11406 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent d61a511 commit f04387e

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

lib/internal/freelist.js

+20-19
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
'use strict';
22

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+
}
1610

11+
alloc() {
12+
return this.list.length ? this.list.pop() :
13+
this.ctor.apply(this, arguments);
14+
}
1715

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;
2222
}
23-
return false;
24-
};
23+
}
24+
25+
module.exports = {FreeList};

0 commit comments

Comments
 (0)