mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 09:38:06 +02:00
Re-factor the LocalTilingPatternCache
to cache by Ref rather than Name (PR 12458 follow-up, issue 13780)
This way there cannot be any *incorrect* cache hits, since Refs are guaranteed to be unique. Please note that the reason for caching by Ref rather than doing something along the lines of the `localShadingPatternCache` (which uses a `Map` directly), is that TilingPatterns are streams and those cannot be cached on the `XRef`-instance (this way we avoid unnecessary parsing).
This commit is contained in:
parent
8ee5acd85d
commit
5f25fea0fe
2 changed files with 16 additions and 26 deletions
|
@ -135,25 +135,18 @@ class LocalGStateCache extends BaseLocalCache {
|
|||
}
|
||||
|
||||
class LocalTilingPatternCache extends BaseLocalCache {
|
||||
set(name, ref = null, data) {
|
||||
if (typeof name !== "string") {
|
||||
throw new Error(
|
||||
'LocalTilingPatternCache.set - expected "name" argument.'
|
||||
);
|
||||
constructor(options) {
|
||||
super({ onlyRefs: true });
|
||||
}
|
||||
|
||||
set(name = null, ref, data) {
|
||||
if (!ref) {
|
||||
throw new Error('LocalTilingPatternCache.set - expected "ref" argument.');
|
||||
}
|
||||
if (ref) {
|
||||
if (this._imageCache.has(ref)) {
|
||||
return;
|
||||
}
|
||||
this._nameRefMap.set(name, ref);
|
||||
this._imageCache.put(ref, data);
|
||||
if (this._imageCache.has(ref)) {
|
||||
return;
|
||||
}
|
||||
// name
|
||||
if (this._imageMap.has(name)) {
|
||||
return;
|
||||
}
|
||||
this._imageMap.set(name, data);
|
||||
this._imageCache.put(ref, data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue