mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Simplify the PDFFunctionFactory._localFunctionCache
initialization (PR 12034 follow-up)
By changing this a `shadow`ed getter, we can simply access it directly and not worry about it being initialized. I have no idea why I didn't just implement it this way in the first place.
This commit is contained in:
parent
2cba290361
commit
cfaf23dee2
1 changed files with 8 additions and 7 deletions
|
@ -20,6 +20,7 @@ import {
|
||||||
info,
|
info,
|
||||||
isBool,
|
isBool,
|
||||||
IsEvalSupportedCached,
|
IsEvalSupportedCached,
|
||||||
|
shadow,
|
||||||
unreachable,
|
unreachable,
|
||||||
} from "../shared/util.js";
|
} from "../shared/util.js";
|
||||||
import { PostScriptLexer, PostScriptParser } from "./ps_parser.js";
|
import { PostScriptLexer, PostScriptParser } from "./ps_parser.js";
|
||||||
|
@ -29,7 +30,6 @@ class PDFFunctionFactory {
|
||||||
constructor({ xref, isEvalSupported = true }) {
|
constructor({ xref, isEvalSupported = true }) {
|
||||||
this.xref = xref;
|
this.xref = xref;
|
||||||
this.isEvalSupported = isEvalSupported !== false;
|
this.isEvalSupported = isEvalSupported !== false;
|
||||||
this._localFunctionCache = null; // Initialized lazily.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
create(fn) {
|
create(fn) {
|
||||||
|
@ -76,9 +76,6 @@ class PDFFunctionFactory {
|
||||||
fnRef = cacheKey.dict && cacheKey.dict.objId;
|
fnRef = cacheKey.dict && cacheKey.dict.objId;
|
||||||
}
|
}
|
||||||
if (fnRef) {
|
if (fnRef) {
|
||||||
if (!this._localFunctionCache) {
|
|
||||||
this._localFunctionCache = new LocalFunctionCache();
|
|
||||||
}
|
|
||||||
const localFunction = this._localFunctionCache.getByRef(fnRef);
|
const localFunction = this._localFunctionCache.getByRef(fnRef);
|
||||||
if (localFunction) {
|
if (localFunction) {
|
||||||
return localFunction;
|
return localFunction;
|
||||||
|
@ -105,12 +102,16 @@ class PDFFunctionFactory {
|
||||||
fnRef = cacheKey.dict && cacheKey.dict.objId;
|
fnRef = cacheKey.dict && cacheKey.dict.objId;
|
||||||
}
|
}
|
||||||
if (fnRef) {
|
if (fnRef) {
|
||||||
if (!this._localFunctionCache) {
|
|
||||||
this._localFunctionCache = new LocalFunctionCache();
|
|
||||||
}
|
|
||||||
this._localFunctionCache.set(/* name = */ null, fnRef, parsedFunction);
|
this._localFunctionCache.set(/* name = */ null, fnRef, parsedFunction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
get _localFunctionCache() {
|
||||||
|
return shadow(this, "_localFunctionCache", new LocalFunctionCache());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toNumberArray(arr) {
|
function toNumberArray(arr) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue