From f04387e9f259070dfa9d7de7b9a6dc15bffe1afa Mon Sep 17 00:00:00 2001 From: James M Snell Date: Wed, 15 Feb 2017 13:49:51 -0800 Subject: [PATCH] lib: refactor internal/freelist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/11406 Reviewed-By: Anna Henningsen Reviewed-By: Michaƫl Zasso --- lib/internal/freelist.js | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/lib/internal/freelist.js b/lib/internal/freelist.js index 580726e872..ed1084753b 100644 --- a/lib/internal/freelist.js +++ b/lib/internal/freelist.js @@ -1,24 +1,25 @@ '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); -}; +class FreeList { + constructor(name, max, ctor) { + this.name = name; + this.ctor = ctor; + this.max = max; + this.list = []; + } + alloc() { + return this.list.length ? this.list.pop() : + this.ctor.apply(this, arguments); + } -exports.FreeList.prototype.free = function(obj) { - if (this.list.length < this.max) { - this.list.push(obj); - return true; + free(obj) { + if (this.list.length < this.max) { + this.list.push(obj); + return true; + } + return false; } - return false; -}; +} + +module.exports = {FreeList};