mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 23:43:09 +01:00
ff2ed3ec85
Remove the hasItems() method from freelist module as it is unused internally. PR-URL: https://github.com/nodejs/node/pull/30744 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Weijia Wang <starkwang@126.com>
31 lines
476 B
JavaScript
31 lines
476 B
JavaScript
'use strict';
|
|
|
|
const {
|
|
ReflectApply,
|
|
} = primordials;
|
|
|
|
class FreeList {
|
|
constructor(name, max, ctor) {
|
|
this.name = name;
|
|
this.ctor = ctor;
|
|
this.max = max;
|
|
this.list = [];
|
|
}
|
|
|
|
alloc() {
|
|
return this.list.length > 0 ?
|
|
this.list.pop() :
|
|
ReflectApply(this.ctor, this, arguments);
|
|
}
|
|
|
|
free(obj) {
|
|
if (this.list.length < this.max) {
|
|
this.list.push(obj);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
module.exports = FreeList;
|