Skip to content

Commit

Permalink
use for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasBa committed Jul 18, 2024
1 parent 5e3808a commit 4a984b0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
18 changes: 4 additions & 14 deletions packages/rrweb/src/record/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,12 +690,7 @@ export default class MutationBuffer {

// iterate breadth first over new nodes (non recursive for performance)
while (genAddsQueue.length) {
const next = genAddsQueue.pop()!;

// Since this is an extremely hot path, do not destructure next
// in order to avoid invoking the iterator protocol
const n = next[0];
const target = next[1];
const [n, target] = genAddsQueue.pop()!;

// this node was already recorded in other buffer, ignore it
if (this.processedNodeManager.inOtherBuffer(n, this)) continue;
Expand Down Expand Up @@ -728,25 +723,20 @@ export default class MutationBuffer {

for (let j = n.childNodes.length - 1; j >= 0; j--) {
const childN = n.childNodes[j];
if (this.movedSet.has(childN) || this.addedSet.has(childN))
return;

genAddsQueue.push([childN, undefined]);
}
if (hasShadowRoot(n)) {
for (let j = n.shadowRoot.childNodes.length - 1; j >= 0; j--) {
const childN = n.shadowRoot.childNodes[j];
if (this.movedSet.has(childN) || this.addedSet.has(childN))
return;

this.processedNodeManager.add(childN, this);
genAddsQueue.push([childN, n]);
}
}
}
}

m.removedNodes.forEach((n) => {
for(let i = 0; i < m.removedNodes.length; i++) {
const n = m.removedNodes[i];
const nodeId = this.mirror.getId(n);
const parentId = isShadowRoot(m.target)
? this.mirror.getId(m.target.host)
Expand Down Expand Up @@ -793,7 +783,7 @@ export default class MutationBuffer {
});
}
this.mapRemoves.push(n);
});
};
break;
}
default:
Expand Down
5 changes: 1 addition & 4 deletions packages/rrweb/src/record/processed-node-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ import type MutationBuffer from './mutation';
*/
export default class ProcessedNodeManager {
private nodeMap: WeakMap<Node, Set<MutationBuffer>> = new WeakMap();

private active = false;

public inOtherBuffer(node: Node, thisBuffer: MutationBuffer) {
const buffers = this.nodeMap.get(node);
return (
buffers && Array.from(buffers).some((buffer) => buffer !== thisBuffer)
);
return buffers?.has(thisBuffer)
}

public add(node: Node, buffer: MutationBuffer) {
Expand Down

0 comments on commit 4a984b0

Please sign in to comment.