Merge pull request #12057 from Snuffleupagus/BaseLocalCache-onlyRefs

Allow `BaseLocalCache` to, optionally, only allocate storage for caching of references (PR 12034 follow-up)
This commit is contained in:
Tim van der Meij 2020-07-05 14:05:45 +02:00 committed by GitHub
commit 4ef43ca44b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,12 +18,14 @@ import { assert, info, shadow, unreachable } from "../shared/util.js";
import { RefSetCache } from "./primitives.js";
class BaseLocalCache {
constructor() {
constructor(options) {
if (this.constructor === BaseLocalCache) {
unreachable("Cannot initialize BaseLocalCache.");
}
this._nameRefMap = new Map();
this._imageMap = new Map();
if (!options || !options.onlyRefs) {
this._nameRefMap = new Map();
this._imageMap = new Map();
}
this._imageCache = new RefSetCache();
}
@ -92,6 +94,10 @@ class LocalColorSpaceCache extends BaseLocalCache {
}
class LocalFunctionCache extends BaseLocalCache {
constructor(options) {
super({ onlyRefs: true });
}
getByName(name) {
unreachable("Should not call `getByName` method.");
}