Skip to content

Commit

Permalink
Improve persistentIdSet performance
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelWest22 committed Dec 19, 2024
1 parent 35c06a1 commit 7fe3f25
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/idiomorph.js
Original file line number Diff line number Diff line change
Expand Up @@ -1204,15 +1204,17 @@ var Idiomorph = (function () {
* @returns {Set<string>} the id set of all persistent nodes that exist in both old and new content
*/
function persistentIdSet(oldContent, newContent) {
let idSet = new Set();
let matchIdSet = new Set();
let oldIdSet = new Set();
for (const oldNode of nodesWithIds(oldContent)) {
for (const newNode of nodesWithIds(newContent)) {
if (oldNode.id === newNode.id) {
idSet.add(oldNode.id);
}
oldIdSet.add(oldNode.id);
}
for (const newNode of nodesWithIds(newContent)) {
if (oldIdSet.has(newNode.id)) {
matchIdSet.add(newNode.id);
}
}
return idSet;
return matchIdSet;
}

//=============================================================================
Expand Down

0 comments on commit 7fe3f25

Please sign in to comment.