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.
This commit is contained in:
Jonas Jenwald 2022-11-11 12:20:43 +01:00
parent d6cd48e12a
commit bab1097db3

View File

@ -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("");
}