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) {
|
||||
const currentPath = _paths[0];
|
||||
const children = {};
|
||||
const children = new Map();
|
||||
let declareTimestamp = 0;
|
||||
let declareAttributeTimestamps;
|
||||
let declareAttributeValues;
|
||||
@@ -1830,15 +1830,18 @@ function processDeclarations(
|
||||
for (const path of _paths) {
|
||||
if (path.length > currentPath.length) {
|
||||
const fragment = path[currentPath.length];
|
||||
if (!children[fragment]) {
|
||||
children[fragment] = [];
|
||||
let child = children.get(fragment);
|
||||
if (!child) {
|
||||
if (path.length > currentPath.length + 1) {
|
||||
// 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));
|
||||
children[fragment].push(p);
|
||||
child = [p];
|
||||
} else {
|
||||
child = [];
|
||||
}
|
||||
children.set(fragment, child);
|
||||
}
|
||||
children[fragment].push(path);
|
||||
child.push(path);
|
||||
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.
|
||||
if (
|
||||
((currentPath.wildcard ^ children[child][0].wildcard) &
|
||||
((currentPath.wildcard ^ child[0].wildcard) &
|
||||
((1 << currentPath.length) - 1)) >>
|
||||
leafParam.length ===
|
||||
0
|
||||
) {
|
||||
if (child !== "*" && children["*"])
|
||||
children[child] = children[child].concat(children["*"]);
|
||||
|
||||
func(leafParam, leafIsObject, leafTimestamp, children[child]);
|
||||
if (fragment !== "*") {
|
||||
const wildcardChild = children.get("*");
|
||||
if (wildcardChild) child = child.concat(wildcardChild);
|
||||
}
|
||||
func(leafParam, leafIsObject, leafTimestamp, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user