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;