mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 09:38:06 +02:00
Inline the addPageIndex
method in GlobalImageCache.shouldCache
When the `GlobalImageCache` implementation originally landed, back in PR 11912, the image handling was slightly more complex (with e.g. browser-decoding of some JPEG images). At this point it no longer seems necessary to manually handle pageIndexes in this way, and we should be able to simply inline that in the `GlobalImageCache.shouldCache` method.
This commit is contained in:
parent
9eea9993df
commit
bb1228cb64
2 changed files with 11 additions and 19 deletions
|
@ -215,27 +215,20 @@ class GlobalImageCache {
|
|||
}
|
||||
|
||||
shouldCache(ref, pageIndex) {
|
||||
const pageIndexSet = this._refCache.get(ref);
|
||||
const numPages = pageIndexSet
|
||||
? pageIndexSet.size + (pageIndexSet.has(pageIndex) ? 0 : 1)
|
||||
: 1;
|
||||
|
||||
if (numPages < GlobalImageCache.NUM_PAGES_THRESHOLD) {
|
||||
return false;
|
||||
}
|
||||
if (!this._imageCache.has(ref) && this._cacheLimitReached) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
addPageIndex(ref, pageIndex) {
|
||||
let pageIndexSet = this._refCache.get(ref);
|
||||
if (!pageIndexSet) {
|
||||
pageIndexSet = new Set();
|
||||
this._refCache.put(ref, pageIndexSet);
|
||||
}
|
||||
pageIndexSet.add(pageIndex);
|
||||
|
||||
if (pageIndexSet.size < GlobalImageCache.NUM_PAGES_THRESHOLD) {
|
||||
return false;
|
||||
}
|
||||
if (!this._imageCache.has(ref) && this._cacheLimitReached) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -273,7 +266,7 @@ class GlobalImageCache {
|
|||
setData(ref, data) {
|
||||
if (!this._refCache.has(ref)) {
|
||||
throw new Error(
|
||||
'GlobalImageCache.setData - expected "addPageIndex" to have been called.'
|
||||
'GlobalImageCache.setData - expected "shouldCache" to have been called.'
|
||||
);
|
||||
}
|
||||
if (this._imageCache.has(ref)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue