Preallocating in LinkedList's toArray method (#5488)

This commit is contained in:
Cameron Fischer
2021-02-11 13:39:50 +00:00
committed by GitHub
parent bfa062f23d
commit c0dc2669c0
+3 -2
View File
@@ -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;
};