Merge pull request #10863 from Snuffleupagus/clearPrimitiveCaches

Ensure that the `Cmd`/`Name`/`Ref` caches are cleared when running other `cleanup` code
This commit is contained in:
Tim van der Meij 2019-05-26 15:15:00 +02:00 committed by GitHub
commit f652cf8e5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 7 deletions

View File

@ -20,8 +20,8 @@ import {
warn
} from '../shared/util';
import {
Dict, isCmd, isDict, isName, isRef, isRefsEqual, isStream, Ref, RefSet,
RefSetCache
clearPrimitiveCaches, Dict, isCmd, isDict, isName, isRef, isRefsEqual,
isStream, Ref, RefSet, RefSetCache
} from './primitives';
import { Lexer, Parser } from './parser';
import {
@ -662,6 +662,7 @@ class Catalog {
}
cleanup() {
clearPrimitiveCaches();
this.pageKidsCountCache.clear();
const promises = [];

View File

@ -19,36 +19,44 @@ import { assert } from '../shared/util';
var EOF = {};
var Name = (function NameClosure() {
let nameCache = Object.create(null);
function Name(name) {
this.name = name;
}
Name.prototype = {};
var nameCache = Object.create(null);
Name.get = function Name_get(name) {
var nameValue = nameCache[name];
return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
};
Name._clearCache = function() {
nameCache = Object.create(null);
};
return Name;
})();
var Cmd = (function CmdClosure() {
let cmdCache = Object.create(null);
function Cmd(cmd) {
this.cmd = cmd;
}
Cmd.prototype = {};
var cmdCache = Object.create(null);
Cmd.get = function Cmd_get(cmd) {
var cmdValue = cmdCache[cmd];
return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
};
Cmd._clearCache = function() {
cmdCache = Object.create(null);
};
return Cmd;
})();
@ -178,7 +186,7 @@ var Dict = (function DictClosure() {
})();
var Ref = (function RefClosure() {
const refCache = Object.create(null);
let refCache = Object.create(null);
function Ref(num, gen) {
this.num = num;
@ -202,6 +210,10 @@ var Ref = (function RefClosure() {
return (refValue ? refValue : (refCache[key] = new Ref(num, gen)));
};
Ref._clearCache = function() {
refCache = Object.create(null);
};
return Ref;
})();
@ -299,8 +311,15 @@ function isStream(v) {
return typeof v === 'object' && v !== null && v.getBytes !== undefined;
}
function clearPrimitiveCaches() {
Cmd._clearCache();
Name._clearCache();
Ref._clearCache();
}
export {
EOF,
clearPrimitiveCaches,
Cmd,
Dict,
Name,