From 3369f9a7837ea776beb2d35a690ebf934aa07ce7 Mon Sep 17 00:00:00 2001
From: Jonas Jenwald <jonas.jenwald@gmail.com>
Date: Thu, 12 Aug 2021 11:31:41 +0200
Subject: [PATCH] Move some validation, in `Dict.merge`, used during merging of
 sub-dictionaries (PR 13775 follow-up)

By not adding any additional non-`Dict` entries to the list of candidates for merging of sub-dictionaries, we can very slightly reduce the amount of parsing required by not having to *again* iterate through unmergeable data.
---
 src/core/primitives.js | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/core/primitives.js b/src/core/primitives.js
index a12231262..334af49b7 100644
--- a/src/core/primitives.js
+++ b/src/core/primitives.js
@@ -197,8 +197,11 @@ class Dict {
         if (property === undefined) {
           property = [];
           properties.set(key, property);
-        } else if (!mergeSubDicts) {
-          continue; // Ignore additional entries for a "shallow" merge.
+        } else if (!mergeSubDicts || !(value instanceof Dict)) {
+          // Ignore additional entries, if either:
+          //  - This is a "shallow" merge, where only the first element matters.
+          //  - The value is *not* a `Dict`, since other types cannot be merged.
+          continue;
         }
         property.push(value);
       }
@@ -211,9 +214,6 @@ class Dict {
       const subDict = new Dict(xref);
 
       for (const dict of values) {
-        if (!(dict instanceof Dict)) {
-          continue;
-        }
         for (const [key, value] of Object.entries(dict._map)) {
           if (subDict._map[key] === undefined) {
             subDict._map[key] = value;