Replace object with Map for performance
This commit is contained in:
1 parent
09e6a360af
commit
d3bb5ae16f
1 file changed
+15
-11
+15
-11
@@ -1817,7 +1817,7 @@ function processDeclarations(
|
|||||||
|
|
||||||
function func(leafParam, leafIsObject, leafTimestamp, _paths) {
|
function func(leafParam, leafIsObject, leafTimestamp, _paths) {
|
||||||
const currentPath = _paths[0];
|
const currentPath = _paths[0];
|
||||||
const children = {};
|
const children = new Map();
|
||||||
let declareTimestamp = 0;
|
let declareTimestamp = 0;
|
||||||
let declareAttributeTimestamps;
|
let declareAttributeTimestamps;
|
||||||
let declareAttributeValues;
|
let declareAttributeValues;
|
||||||
@@ -1830,15 +1830,18 @@ function processDeclarations(
|
|||||||
for (const path of _paths) {
|
for (const path of _paths) {
|
||||||
if (path.length > currentPath.length) {
|
if (path.length > currentPath.length) {
|
||||||
const fragment = path[currentPath.length];
|
const fragment = path[currentPath.length];
|
||||||
if (!children[fragment]) {
|
let child = children.get(fragment);
|
||||||
children[fragment] = [];
|
if (!child) {
|
||||||
if (path.length > currentPath.length + 1) {
|
if (path.length > currentPath.length + 1) {
|
||||||
// This is to ensure we don't descend more than one step at a time
|
// This is to ensure we don't descend more than one step at a time
|
||||||
const p = common.addPathMeta(path.slice(0, currentPath.length + 1));
|
const p = common.addPathMeta(path.slice(0, currentPath.length + 1));
|
||||||
children[fragment].push(p);
|
child = [p];
|
||||||
|
} else {
|
||||||
|
child = [];
|
||||||
}
|
}
|
||||||
|
children.set(fragment, child);
|
||||||
}
|
}
|
||||||
children[fragment].push(path);
|
child.push(path);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2041,18 +2044,19 @@ function processDeclarations(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const child of Object.keys(children)) {
|
for (let [fragment, child] of children) {
|
||||||
// This fine expression avoids duplicate visits, don't ask.
|
// This fine expression avoids duplicate visits, don't ask.
|
||||||
if (
|
if (
|
||||||
((currentPath.wildcard ^ children[child][0].wildcard) &
|
((currentPath.wildcard ^ child[0].wildcard) &
|
||||||
((1 << currentPath.length) - 1)) >>
|
((1 << currentPath.length) - 1)) >>
|
||||||
leafParam.length ===
|
leafParam.length ===
|
||||||
0
|
0
|
||||||
) {
|
) {
|
||||||
if (child !== "*" && children["*"])
|
if (fragment !== "*") {
|
||||||
children[child] = children[child].concat(children["*"]);
|
const wildcardChild = children.get("*");
|
||||||
|
if (wildcardChild) child = child.concat(wildcardChild);
|
||||||
func(leafParam, leafIsObject, leafTimestamp, children[child]);
|
}
|
||||||
|
func(leafParam, leafIsObject, leafTimestamp, child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user