Inline a couple of isRef/isDict checks in the ObjectLoader code

As we've seen in numerous other cases, avoiding unnecessary function calls is never a bad thing (even if the effect is probably tiny here).
This commit is contained in:
Jonas Jenwald 2019-10-29 18:12:35 +01:00
parent 1133dbac33
commit 2d35a49dd8

View File

@ -2038,13 +2038,13 @@ var FileSpec = (function FileSpecClosure() {
*/ */
let ObjectLoader = (function() { let ObjectLoader = (function() {
function mayHaveChildren(value) { function mayHaveChildren(value) {
return isRef(value) || isDict(value) || Array.isArray(value) || return (value instanceof Ref) || (value instanceof Dict) ||
isStream(value); Array.isArray(value) || isStream(value);
} }
function addChildren(node, nodesToVisit) { function addChildren(node, nodesToVisit) {
if (isDict(node) || isStream(node)) { if ((node instanceof Dict) || isStream(node)) {
let dict = isDict(node) ? node : node.dict; let dict = (node instanceof Dict) ? node : node.dict;
let dictKeys = dict.getKeys(); let dictKeys = dict.getKeys();
for (let i = 0, ii = dictKeys.length; i < ii; i++) { for (let i = 0, ii = dictKeys.length; i < ii; i++) {
let rawValue = dict.getRaw(dictKeys[i]); let rawValue = dict.getRaw(dictKeys[i]);
@ -2104,7 +2104,7 @@ let ObjectLoader = (function() {
let currentNode = nodesToVisit.pop(); let currentNode = nodesToVisit.pop();
// Only references or chunked streams can cause missing data exceptions. // Only references or chunked streams can cause missing data exceptions.
if (isRef(currentNode)) { if (currentNode instanceof Ref) {
// Skip nodes that have already been visited. // Skip nodes that have already been visited.
if (this.refSet.has(currentNode)) { if (this.refSet.has(currentNode)) {
continue; continue;
@ -2144,7 +2144,7 @@ let ObjectLoader = (function() {
let node = nodesToRevisit[i]; let node = nodesToRevisit[i];
// Remove any reference nodes from the current `RefSet` so they // Remove any reference nodes from the current `RefSet` so they
// aren't skipped when we revist them. // aren't skipped when we revist them.
if (isRef(node)) { if (node instanceof Ref) {
this.refSet.remove(node); this.refSet.remove(node);
} }
} }