Merge pull request #16368 from Snuffleupagus/rm-GlobalImageCache-addPageIndex
Inline the `addPageIndex` method in `GlobalImageCache.shouldCache`
This commit is contained in:
commit
667085ee33
@ -822,10 +822,9 @@ class PartialEvaluator {
|
|||||||
if (imageRef) {
|
if (imageRef) {
|
||||||
this._regionalImageCache.set(/* name = */ null, imageRef, cacheData);
|
this._regionalImageCache.set(/* name = */ null, imageRef, cacheData);
|
||||||
|
|
||||||
assert(!isInline, "Cannot cache an inline image globally.");
|
|
||||||
this.globalImageCache.addPageIndex(imageRef, this.pageIndex);
|
|
||||||
|
|
||||||
if (cacheGlobally) {
|
if (cacheGlobally) {
|
||||||
|
assert(!isInline, "Cannot cache an inline image globally.");
|
||||||
|
|
||||||
this.globalImageCache.setData(imageRef, {
|
this.globalImageCache.setData(imageRef, {
|
||||||
objId,
|
objId,
|
||||||
fn: OPS.paintImageXObject,
|
fn: OPS.paintImageXObject,
|
||||||
|
@ -208,27 +208,20 @@ class GlobalImageCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
shouldCache(ref, pageIndex) {
|
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);
|
let pageIndexSet = this._refCache.get(ref);
|
||||||
if (!pageIndexSet) {
|
if (!pageIndexSet) {
|
||||||
pageIndexSet = new Set();
|
pageIndexSet = new Set();
|
||||||
this._refCache.put(ref, pageIndexSet);
|
this._refCache.put(ref, pageIndexSet);
|
||||||
}
|
}
|
||||||
pageIndexSet.add(pageIndex);
|
pageIndexSet.add(pageIndex);
|
||||||
|
|
||||||
|
if (pageIndexSet.size < GlobalImageCache.NUM_PAGES_THRESHOLD) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!this._imageCache.has(ref) && this._cacheLimitReached) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -266,7 +259,7 @@ class GlobalImageCache {
|
|||||||
setData(ref, data) {
|
setData(ref, data) {
|
||||||
if (!this._refCache.has(ref)) {
|
if (!this._refCache.has(ref)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'GlobalImageCache.setData - expected "addPageIndex" to have been called.'
|
'GlobalImageCache.setData - expected "shouldCache" to have been called.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (this._imageCache.has(ref)) {
|
if (this._imageCache.has(ref)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user