From c0dc2669c0d617d739ea58277131b0760c757020 Mon Sep 17 00:00:00 2001 From: Cameron Fischer Date: Thu, 11 Feb 2021 08:39:50 -0500 Subject: [PATCH] Preallocating in LinkedList's toArray method (#5488) --- core/modules/utils/linked-list.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/modules/utils/linked-list.js b/core/modules/utils/linked-list.js index 3fdc7f8b2..06242b454 100644 --- a/core/modules/utils/linked-list.js +++ b/core/modules/utils/linked-list.js @@ -89,8 +89,9 @@ LinkedList.prototype.each = function(callback) { }; LinkedList.prototype.toArray = function() { - var output = []; - this.each(function(value) { output.push(value); }); + var output = new Array(this.length), + index = 0; + this.each(function(value) { output[index++] = value; }); return output; };