Merge pull request #16332 from Snuffleupagus/rm-primitives-closures

Remove the remaining unnecessary closures in the `src/core/primitives.js` file
This commit is contained in:
Jonas Jenwald 2023-04-22 15:55:10 +02:00 committed by GitHub
commit 6e1b234c6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,11 +18,17 @@ import { assert, shadow, unreachable } from "../shared/util.js";
const CIRCULAR_REF = Symbol("CIRCULAR_REF");
const EOF = Symbol("EOF");
const Name = (function NameClosure() {
let nameCache = Object.create(null);
let CmdCache = Object.create(null);
let NameCache = Object.create(null);
let RefCache = Object.create(null);
// eslint-disable-next-line no-shadow
class Name {
function clearPrimitiveCaches() {
CmdCache = Object.create(null);
NameCache = Object.create(null);
RefCache = Object.create(null);
}
class Name {
constructor(name) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
@ -35,22 +41,11 @@ const Name = (function NameClosure() {
static get(name) {
// eslint-disable-next-line no-restricted-syntax
return nameCache[name] || (nameCache[name] = new Name(name));
return NameCache[name] || (NameCache[name] = new Name(name));
}
}
static _clearCache() {
nameCache = Object.create(null);
}
}
return Name;
})();
const Cmd = (function CmdClosure() {
let cmdCache = Object.create(null);
// eslint-disable-next-line no-shadow
class Cmd {
class Cmd {
constructor(cmd) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
@ -63,16 +58,9 @@ const Cmd = (function CmdClosure() {
static get(cmd) {
// eslint-disable-next-line no-restricted-syntax
return cmdCache[cmd] || (cmdCache[cmd] = new Cmd(cmd));
return CmdCache[cmd] || (CmdCache[cmd] = new Cmd(cmd));
}
static _clearCache() {
cmdCache = Object.create(null);
}
}
return Cmd;
})();
}
const nonSerializable = function nonSerializableClosure() {
return nonSerializable; // Creating closure on some variable.
@ -276,11 +264,7 @@ class Dict {
}
}
const Ref = (function RefClosure() {
let refCache = Object.create(null);
// eslint-disable-next-line no-shadow
class Ref {
class Ref {
constructor(num, gen) {
this.num = num;
this.gen = gen;
@ -298,16 +282,9 @@ const Ref = (function RefClosure() {
static get(num, gen) {
const key = gen === 0 ? `${num}R` : `${num}R${gen}`;
// eslint-disable-next-line no-restricted-syntax
return refCache[key] || (refCache[key] = new Ref(num, gen));
return RefCache[key] || (RefCache[key] = new Ref(num, gen));
}
static _clearCache() {
refCache = Object.create(null);
}
}
return Ref;
})();
}
// The reference is identified by number and generation.
// This structure stores only one instance of the reference.
@ -402,12 +379,6 @@ function isRefsEqual(v1, v2) {
return v1.num === v2.num && v1.gen === v2.gen;
}
function clearPrimitiveCaches() {
Cmd._clearCache();
Name._clearCache();
Ref._clearCache();
}
export {
CIRCULAR_REF,
clearPrimitiveCaches,