mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-08-01 11:57:20 +02:00
Re-factor the CachedCanvases class to use a Map internally
This commit is contained in:
parent
d38cddf2b6
commit
2cc53270f3
@ -205,33 +205,32 @@ function mirrorContextOperations(ctx, destCtx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class CachedCanvases {
|
class CachedCanvases {
|
||||||
|
#cache = new Map();
|
||||||
|
|
||||||
constructor(canvasFactory) {
|
constructor(canvasFactory) {
|
||||||
this.canvasFactory = canvasFactory;
|
this.canvasFactory = canvasFactory;
|
||||||
this.cache = Object.create(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getCanvas(id, width, height) {
|
getCanvas(id, width, height) {
|
||||||
let canvasEntry;
|
let canvasEntry = this.#cache.get(id);
|
||||||
if (this.cache[id] !== undefined) {
|
if (canvasEntry) {
|
||||||
canvasEntry = this.cache[id];
|
|
||||||
this.canvasFactory.reset(canvasEntry, width, height);
|
this.canvasFactory.reset(canvasEntry, width, height);
|
||||||
} else {
|
} else {
|
||||||
canvasEntry = this.canvasFactory.create(width, height);
|
canvasEntry = this.canvasFactory.create(width, height);
|
||||||
this.cache[id] = canvasEntry;
|
this.#cache.set(id, canvasEntry);
|
||||||
}
|
}
|
||||||
return canvasEntry;
|
return canvasEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(id) {
|
delete(id) {
|
||||||
delete this.cache[id];
|
this.#cache.delete(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
for (const id in this.cache) {
|
for (const canvasEntry of this.#cache.values()) {
|
||||||
const canvasEntry = this.cache[id];
|
|
||||||
this.canvasFactory.destroy(canvasEntry);
|
this.canvasFactory.destroy(canvasEntry);
|
||||||
delete this.cache[id];
|
|
||||||
}
|
}
|
||||||
|
this.#cache.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user