Remove the remaining unnecessary closures in the src/core/primitives.js
file
This commit is contained in:
parent
e304423ba1
commit
9cb3236ac0
@ -18,10 +18,16 @@ 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);
|
||||
|
||||
function clearPrimitiveCaches() {
|
||||
CmdCache = Object.create(null);
|
||||
NameCache = Object.create(null);
|
||||
RefCache = Object.create(null);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-shadow
|
||||
class Name {
|
||||
constructor(name) {
|
||||
if (
|
||||
@ -35,21 +41,10 @@ const Name = (function NameClosure() {
|
||||
|
||||
static get(name) {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
return nameCache[name] || (nameCache[name] = new Name(name));
|
||||
}
|
||||
|
||||
static _clearCache() {
|
||||
nameCache = Object.create(null);
|
||||
return NameCache[name] || (NameCache[name] = new Name(name));
|
||||
}
|
||||
}
|
||||
|
||||
return Name;
|
||||
})();
|
||||
|
||||
const Cmd = (function CmdClosure() {
|
||||
let cmdCache = Object.create(null);
|
||||
|
||||
// eslint-disable-next-line no-shadow
|
||||
class Cmd {
|
||||
constructor(cmd) {
|
||||
if (
|
||||
@ -63,17 +58,10 @@ const Cmd = (function CmdClosure() {
|
||||
|
||||
static get(cmd) {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
return cmdCache[cmd] || (cmdCache[cmd] = new Cmd(cmd));
|
||||
}
|
||||
|
||||
static _clearCache() {
|
||||
cmdCache = Object.create(null);
|
||||
return CmdCache[cmd] || (CmdCache[cmd] = new Cmd(cmd));
|
||||
}
|
||||
}
|
||||
|
||||
return Cmd;
|
||||
})();
|
||||
|
||||
const nonSerializable = function nonSerializableClosure() {
|
||||
return nonSerializable; // Creating closure on some variable.
|
||||
};
|
||||
@ -276,10 +264,6 @@ class Dict {
|
||||
}
|
||||
}
|
||||
|
||||
const Ref = (function RefClosure() {
|
||||
let refCache = Object.create(null);
|
||||
|
||||
// eslint-disable-next-line no-shadow
|
||||
class Ref {
|
||||
constructor(num, gen) {
|
||||
this.num = num;
|
||||
@ -298,17 +282,10 @@ 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));
|
||||
}
|
||||
|
||||
static _clearCache() {
|
||||
refCache = Object.create(null);
|
||||
return RefCache[key] || (RefCache[key] = new Ref(num, gen));
|
||||
}
|
||||
}
|
||||
|
||||
return Ref;
|
||||
})();
|
||||
|
||||
// The reference is identified by number and generation.
|
||||
// This structure stores only one instance of the reference.
|
||||
class RefSet {
|
||||
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user