From 8857a81c8d4f87e9bccc8d6edc98da264d1a790e Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 30 May 2019 16:25:48 +0200 Subject: [PATCH] Re-use, rather than re-creating, some `Array`s when resetting them in `src/display/api.js` Calling `someArray = []` will create a new Array, which seems completely unnecessary when it's sufficient to just call `someArray.length = 0` to achieve the same effect. Even though I cannot imagine these particular cases having any noticeable performance impact, similar changes were made in `core/` code years ago since it's apparently more efficient memory wise. --- src/display/api.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/display/api.js b/src/display/api.js index 60b7aa63a..c6fbd182f 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -1377,7 +1377,7 @@ class LoopbackPort { } terminate() { - this._listeners = []; + this._listeners.length = 0; } } @@ -1760,8 +1760,8 @@ class WorkerTransport { waitOn.push(page._destroy()); } }); - this.pageCache = []; - this.pagePromises = []; + this.pageCache.length = 0; + this.pagePromises.length = 0; // We also need to wait for the worker to finish its long running tasks. const terminated = this.messageHandler.sendWithPromise('Terminate', null); waitOn.push(terminated);