From bab1097db31e1d9a2b3588d2db8dcb079e4ba061 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 11 Nov 2022 12:20:43 +0100 Subject: [PATCH] Remove the constructor in the `StatTimer` class With modern EcmaScript features, we can define these fields directly instead. Please note that for backwards compatibility purposes they are still public as before, however note that this functionality is *disabled* by default (see the `pdfBug` API option). Also, we can (slightly) simplify the two loops used in the `toString` method. --- src/display/display_utils.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/display/display_utils.js b/src/display/display_utils.js index 0c2c5febb..1d04f0efa 100644 --- a/src/display/display_utils.js +++ b/src/display/display_utils.js @@ -389,10 +389,9 @@ function getPdfFilenameFromUrl(url, defaultFilename = "document.pdf") { } class StatTimer { - constructor() { - this.started = Object.create(null); - this.times = []; - } + started = Object.create(null); + + times = []; time(name) { if (name in this.started) { @@ -418,15 +417,11 @@ class StatTimer { // Find the longest name for padding purposes. const outBuf = []; let longest = 0; - for (const time of this.times) { - const name = time.name; - if (name.length > longest) { - longest = name.length; - } + for (const { name } of this.times) { + longest = Math.max(name.length, longest); } - for (const time of this.times) { - const duration = time.end - time.start; - outBuf.push(`${time.name.padEnd(longest)} ${duration}ms\n`); + for (const { name, start, end } of this.times) { + outBuf.push(`${name.padEnd(longest)} ${end - start}ms\n`); } return outBuf.join(""); }