Merge pull request #13904 from Snuffleupagus/fix-LocalTilingPatternCache
Re-factor the LocalTilingPatternCache to cache by Ref rather than Name (PR 12458 follow-up, issue 13780)
This commit is contained in:
commit
1b3382f921
@ -795,7 +795,6 @@ class PartialEvaluator {
|
|||||||
patternDict,
|
patternDict,
|
||||||
operatorList,
|
operatorList,
|
||||||
task,
|
task,
|
||||||
cacheKey,
|
|
||||||
localTilingPatternCache
|
localTilingPatternCache
|
||||||
) {
|
) {
|
||||||
// Create an IR of the pattern code.
|
// Create an IR of the pattern code.
|
||||||
@ -825,8 +824,8 @@ class PartialEvaluator {
|
|||||||
operatorList.addDependencies(tilingOpList.dependencies);
|
operatorList.addDependencies(tilingOpList.dependencies);
|
||||||
operatorList.addOp(fn, tilingPatternIR);
|
operatorList.addOp(fn, tilingPatternIR);
|
||||||
|
|
||||||
if (cacheKey) {
|
if (patternDict.objId) {
|
||||||
localTilingPatternCache.set(cacheKey, patternDict.objId, {
|
localTilingPatternCache.set(/* name = */ null, patternDict.objId, {
|
||||||
operatorListIR,
|
operatorListIR,
|
||||||
dict: patternDict,
|
dict: patternDict,
|
||||||
});
|
});
|
||||||
@ -1356,9 +1355,11 @@ class PartialEvaluator {
|
|||||||
const patternName = args.pop();
|
const patternName = args.pop();
|
||||||
// SCN/scn applies patterns along with normal colors
|
// SCN/scn applies patterns along with normal colors
|
||||||
if (patternName instanceof Name) {
|
if (patternName instanceof Name) {
|
||||||
const name = patternName.name;
|
const rawPattern = patterns.getRaw(patternName.name);
|
||||||
|
|
||||||
const localTilingPattern = localTilingPatternCache.getByName(name);
|
const localTilingPattern =
|
||||||
|
rawPattern instanceof Ref &&
|
||||||
|
localTilingPatternCache.getByRef(rawPattern);
|
||||||
if (localTilingPattern) {
|
if (localTilingPattern) {
|
||||||
try {
|
try {
|
||||||
const color = cs.base ? cs.base.getRgb(args, 0) : null;
|
const color = cs.base ? cs.base.getRgb(args, 0) : null;
|
||||||
@ -1373,11 +1374,8 @@ class PartialEvaluator {
|
|||||||
// Handle any errors during normal TilingPattern parsing.
|
// Handle any errors during normal TilingPattern parsing.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: Attempt to lookup cached TilingPatterns by reference as well,
|
|
||||||
// if and only if there are PDF documents where doing so would
|
|
||||||
// significantly improve performance.
|
|
||||||
|
|
||||||
const pattern = patterns.get(name);
|
const pattern = this.xref.fetchIfRef(rawPattern);
|
||||||
if (pattern) {
|
if (pattern) {
|
||||||
const dict = isStream(pattern) ? pattern.dict : pattern;
|
const dict = isStream(pattern) ? pattern.dict : pattern;
|
||||||
const typeNum = dict.get("PatternType");
|
const typeNum = dict.get("PatternType");
|
||||||
@ -1392,7 +1390,6 @@ class PartialEvaluator {
|
|||||||
dict,
|
dict,
|
||||||
operatorList,
|
operatorList,
|
||||||
task,
|
task,
|
||||||
/* cacheKey = */ name,
|
|
||||||
localTilingPatternCache
|
localTilingPatternCache
|
||||||
);
|
);
|
||||||
} else if (typeNum === PatternType.SHADING) {
|
} else if (typeNum === PatternType.SHADING) {
|
||||||
|
@ -21,7 +21,9 @@ class BaseLocalCache {
|
|||||||
if (this.constructor === BaseLocalCache) {
|
if (this.constructor === BaseLocalCache) {
|
||||||
unreachable("Cannot initialize BaseLocalCache.");
|
unreachable("Cannot initialize BaseLocalCache.");
|
||||||
}
|
}
|
||||||
if (!options || !options.onlyRefs) {
|
this._onlyRefs = (options && options.onlyRefs) === true;
|
||||||
|
|
||||||
|
if (!this._onlyRefs) {
|
||||||
this._nameRefMap = new Map();
|
this._nameRefMap = new Map();
|
||||||
this._imageMap = new Map();
|
this._imageMap = new Map();
|
||||||
}
|
}
|
||||||
@ -29,6 +31,9 @@ class BaseLocalCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getByName(name) {
|
getByName(name) {
|
||||||
|
if (this._onlyRefs) {
|
||||||
|
unreachable("Should not call `getByName` method.");
|
||||||
|
}
|
||||||
const ref = this._nameRefMap.get(name);
|
const ref = this._nameRefMap.get(name);
|
||||||
if (ref) {
|
if (ref) {
|
||||||
return this.getByRef(ref);
|
return this.getByRef(ref);
|
||||||
@ -97,10 +102,6 @@ class LocalFunctionCache extends BaseLocalCache {
|
|||||||
super({ onlyRefs: true });
|
super({ onlyRefs: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
getByName(name) {
|
|
||||||
unreachable("Should not call `getByName` method.");
|
|
||||||
}
|
|
||||||
|
|
||||||
set(name = null, ref, data) {
|
set(name = null, ref, data) {
|
||||||
if (!ref) {
|
if (!ref) {
|
||||||
throw new Error('LocalFunctionCache.set - expected "ref" argument.');
|
throw new Error('LocalFunctionCache.set - expected "ref" argument.');
|
||||||
@ -134,25 +135,18 @@ class LocalGStateCache extends BaseLocalCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class LocalTilingPatternCache extends BaseLocalCache {
|
class LocalTilingPatternCache extends BaseLocalCache {
|
||||||
set(name, ref = null, data) {
|
constructor(options) {
|
||||||
if (typeof name !== "string") {
|
super({ onlyRefs: true });
|
||||||
throw new Error(
|
}
|
||||||
'LocalTilingPatternCache.set - expected "name" argument.'
|
|
||||||
);
|
set(name = null, ref, data) {
|
||||||
|
if (!ref) {
|
||||||
|
throw new Error('LocalTilingPatternCache.set - expected "ref" argument.');
|
||||||
}
|
}
|
||||||
if (ref) {
|
|
||||||
if (this._imageCache.has(ref)) {
|
if (this._imageCache.has(ref)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._nameRefMap.set(name, ref);
|
|
||||||
this._imageCache.put(ref, data);
|
this._imageCache.put(ref, data);
|
||||||
return;
|
|
||||||
}
|
|
||||||
// name
|
|
||||||
if (this._imageMap.has(name)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this._imageMap.set(name, data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user