mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
All linting now uses the current ESLint 4.3.0 indentation linting. Remove legacy indentation rules. Backport-PR-URL: https://github.com/nodejs/node/pull/14835 PR-URL: https://github.com/nodejs/node/pull/14515 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Claudio Rodriguez <cjrodr@yahoo.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
24 lines
528 B
JavaScript
24 lines
528 B
JavaScript
'use strict';
|
|
|
|
// This is a free list to avoid creating so many of the same object.
|
|
exports.FreeList = function(name, max, constructor) {
|
|
this.name = name;
|
|
this.constructor = constructor;
|
|
this.max = max;
|
|
this.list = [];
|
|
};
|
|
|
|
exports.FreeList.prototype.alloc = function() {
|
|
return this.list.length ? this.list.pop() :
|
|
this.constructor.apply(this, arguments);
|
|
};
|
|
|
|
|
|
exports.FreeList.prototype.free = function(obj) {
|
|
if (this.list.length < this.max) {
|
|
this.list.push(obj);
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|