From 326ddd9ff0c3005f794129534e75774ef678b6c9 Mon Sep 17 00:00:00 2001 From: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> Date: Sun, 7 Mar 2021 15:00:00 +0100 Subject: [PATCH] =?UTF-8?q?lib:=20inline=C2=A0`Array`=C2=A0operations=20in?= =?UTF-8?q?=C2=A0`FreeList`=C2=A0methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Antoine du Hamel --- lib/internal/freelist.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/internal/freelist.js b/lib/internal/freelist.js index ac2b12c4d45a54..d53d6df7b34e7e 100644 --- a/lib/internal/freelist.js +++ b/lib/internal/freelist.js @@ -1,6 +1,7 @@ 'use strict'; const { + ObjectSetPrototypeOf, ReflectApply, } = primordials; @@ -9,18 +10,29 @@ class FreeList { this.name = name; this.ctor = ctor; this.max = max; - this.list = []; + this.list = ObjectSetPrototypeOf([], null); } alloc() { - return this.list.length > 0 ? - this.list.pop() : - ReflectApply(this.ctor, this, arguments); + const { list } = this; + const { length } = list; + + if (length > 0) { + const lastIndex = length - 1; + const result = list[lastIndex]; + list.length = lastIndex; + return result; + } + + return ReflectApply(this.ctor, this, arguments); } free(obj) { - if (this.list.length < this.max) { - this.list.push(obj); + const { list } = this; + const { length } = list; + + if (length < this.max) { + list[length] = obj; return true; } return false;