mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-05-23 19:30:59 +02:00
Re-factor the StatTimer class to track started times in a private Map
This commit is contained in:
parent
a9e439bce1
commit
522f5f85b9
@ -417,28 +417,28 @@ function getPdfFilenameFromUrl(url, defaultFilename = "document.pdf") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class StatTimer {
|
class StatTimer {
|
||||||
started = Object.create(null);
|
#started = new Map();
|
||||||
|
|
||||||
times = [];
|
times = [];
|
||||||
|
|
||||||
time(name) {
|
time(name) {
|
||||||
if (name in this.started) {
|
if (this.#started.has(name)) {
|
||||||
warn(`Timer is already running for ${name}`);
|
warn(`Timer is already running for ${name}`);
|
||||||
}
|
}
|
||||||
this.started[name] = Date.now();
|
this.#started.set(name, Date.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
timeEnd(name) {
|
timeEnd(name) {
|
||||||
if (!(name in this.started)) {
|
if (!this.#started.has(name)) {
|
||||||
warn(`Timer has not been started for ${name}`);
|
warn(`Timer has not been started for ${name}`);
|
||||||
}
|
}
|
||||||
this.times.push({
|
this.times.push({
|
||||||
name,
|
name,
|
||||||
start: this.started[name],
|
start: this.#started.get(name),
|
||||||
end: Date.now(),
|
end: Date.now(),
|
||||||
});
|
});
|
||||||
// Remove timer from started so it can be called again.
|
// Remove timer from started so it can be called again.
|
||||||
delete this.started[name];
|
this.#started.delete(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user