From 684a7b89ac27636735e4e92ebad25d98b81eaeeb Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 17 Jul 2020 13:50:02 +0200 Subject: [PATCH] Remove unnecessary duplication in the `addChildren` helper function (used by the `ObjectLoader`) Besides being fewer lines of code overall, this also avoids *one* `node instanceof Dict` check for both of the `Dict`/`Stream`-cases. --- src/core/obj.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/core/obj.js b/src/core/obj.js index aa468c1e7..fd1986e9d 100644 --- a/src/core/obj.js +++ b/src/core/obj.js @@ -2205,18 +2205,16 @@ const ObjectLoader = (function () { } function addChildren(node, nodesToVisit) { - if (node instanceof Dict || isStream(node)) { - const dict = node instanceof Dict ? node : node.dict; - for (const rawValue of dict.getRawValues()) { - if (mayHaveChildren(rawValue)) { - nodesToVisit.push(rawValue); - } - } - } else if (Array.isArray(node)) { - for (const value of node) { - if (mayHaveChildren(value)) { - nodesToVisit.push(value); - } + if (node instanceof Dict) { + node = node.getRawValues(); + } else if (isStream(node)) { + node = node.dict.getRawValues(); + } else if (!Array.isArray(node)) { + return; + } + for (const rawValue of node) { + if (mayHaveChildren(rawValue)) { + nodesToVisit.push(rawValue); } } }