Skip to content

Commit

Permalink
perf(document): remove unnecessary reset logic
Browse files Browse the repository at this point in the history
Re: #14897
Re: #10295
  • Loading branch information
vkarpov15 committed Sep 25, 2024
1 parent 5851261 commit 95500b6
Showing 1 changed file with 0 additions and 35 deletions.
35 changes: 0 additions & 35 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -3484,44 +3484,9 @@ Document.prototype.$__reset = function reset() {
// Skip for subdocuments
const subdocs = !this.$isSubdocument ? this.$getAllSubdocs() : null;
if (subdocs && subdocs.length > 0) {
const resetArrays = new Set();
for (const subdoc of subdocs) {
const fullPathWithIndexes = subdoc.$__fullPathWithIndexes();
subdoc.$__reset();
if (this.isModified(fullPathWithIndexes) || isParentInit(fullPathWithIndexes)) {
if (subdoc.$isDocumentArrayElement) {
resetArrays.add(subdoc.parentArray());
} else {
const parent = subdoc.$parent();
if (parent === this) {
this.$__.activePaths.clearPath(subdoc.$basePath);
} else if (parent != null && parent.$isSubdocument) {
// If map path underneath subdocument, may end up with a case where
// map path is modified but parent still needs to be reset. See gh-10295
parent.$__reset();
}
}
}
}

for (const array of resetArrays) {
this.$__.activePaths.clearPath(array.$path());
array[arrayAtomicsBackupSymbol] = array[arrayAtomicsSymbol];
array[arrayAtomicsSymbol] = {};
}
}

function isParentInit(path) {
path = path.indexOf('.') === -1 ? [path] : path.split('.');
let cur = '';
for (let i = 0; i < path.length; ++i) {
cur += (cur.length ? '.' : '') + path[i];
if (_this.$__.activePaths[cur] === 'init') {
return true;
}
}

return false;
}

// clear atomics
Expand Down

0 comments on commit 95500b6

Please sign in to comment.