Merge pull request #13775 from Snuffleupagus/Dict-merge-refactor
Remove some duplication in the `Dict.merge` method
This commit is contained in:
commit
9854b85dc1
@ -185,22 +185,8 @@ class Dict {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static merge({ xref, dictArray, mergeSubDicts = false }) {
|
static merge({ xref, dictArray, mergeSubDicts = false }) {
|
||||||
const mergedDict = new Dict(xref);
|
const mergedDict = new Dict(xref),
|
||||||
|
properties = new Map();
|
||||||
if (!mergeSubDicts) {
|
|
||||||
for (const dict of dictArray) {
|
|
||||||
if (!(dict instanceof Dict)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (const [key, value] of Object.entries(dict._map)) {
|
|
||||||
if (mergedDict._map[key] === undefined) {
|
|
||||||
mergedDict._map[key] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return mergedDict.size > 0 ? mergedDict : Dict.empty;
|
|
||||||
}
|
|
||||||
const properties = new Map();
|
|
||||||
|
|
||||||
for (const dict of dictArray) {
|
for (const dict of dictArray) {
|
||||||
if (!(dict instanceof Dict)) {
|
if (!(dict instanceof Dict)) {
|
||||||
@ -211,6 +197,8 @@ class Dict {
|
|||||||
if (property === undefined) {
|
if (property === undefined) {
|
||||||
property = [];
|
property = [];
|
||||||
properties.set(key, property);
|
properties.set(key, property);
|
||||||
|
} else if (!mergeSubDicts) {
|
||||||
|
continue; // Ignore additional entries for a "shallow" merge.
|
||||||
}
|
}
|
||||||
property.push(value);
|
property.push(value);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user