New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce linear search on list traversing #12302
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,24 +67,16 @@ export default class NodePath { | |
|
||
const targetNode = container[key]; | ||
|
||
const paths = pathCache.get(parent) || []; | ||
if (!pathCache.has(parent)) { | ||
let paths = pathCache.get(parent); | ||
if (!paths) { | ||
paths = new Map(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't use a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can create an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh the |
||
pathCache.set(parent, paths); | ||
} | ||
|
||
let path; | ||
|
||
for (let i = 0; i < paths.length; i++) { | ||
const pathCheck = paths[i]; | ||
if (pathCheck.node === targetNode) { | ||
path = pathCheck; | ||
break; | ||
} | ||
} | ||
|
||
let path = paths.get(targetNode); | ||
if (!path) { | ||
path = new NodePath(hub, parent); | ||
paths.push(path); | ||
if (targetNode) paths.set(targetNode, path); | ||
} | ||
|
||
path.setup(parentPath, container, listKey, key); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that when
path.node
isnull
, the current behaviour is to visit this path once but skip other nullishnode
paths sincenull
can be hold in array. In this PR they will all be visited. This could be a breaking change in a way but I think the equality of two paths whosepath.node
is null, is not well-defined.The usage of
WeakSet
is intentional, so we don't leak memory whenpath.node
is GCed.