Skip to content

Commit

Permalink
Revert "perf(document): remove some unnecessary instantiations of opt…
Browse files Browse the repository at this point in the history
…ions objects re: #11541"

This reverts commit 01fc014.
  • Loading branch information
vkarpov15 committed Apr 19, 2022
1 parent a7d3568 commit 905d9bf
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/document.js
Expand Up @@ -1044,7 +1044,8 @@ Document.prototype.$set = function $set(path, val, type, options) {
type = undefined;
}

const merge = options && options.merge;
options = options || {};
const merge = options.merge;
const adhoc = type && type !== true;
const constructing = type === true;
let adhocs;
Expand All @@ -1054,7 +1055,7 @@ Document.prototype.$set = function $set(path, val, type, options) {
let key;
let prefix;

const strict = options && options.strict != null
const strict = 'strict' in options
? options.strict
: this.$__.strictMode;

Expand Down Expand Up @@ -1085,7 +1086,7 @@ Document.prototype.$set = function $set(path, val, type, options) {

// `_skipMinimizeTopLevel` is because we may have deleted the top-level
// nested key to ensure key order.
const _skipMinimizeTopLevel = (options && options._skipMinimizeTopLevel) || false;
const _skipMinimizeTopLevel = options._skipMinimizeTopLevel || false;
if (len === 0 && _skipMinimizeTopLevel) {
delete options._skipMinimizeTopLevel;
if (val) {
Expand Down Expand Up @@ -1555,7 +1556,7 @@ Document.prototype.set = Document.prototype.$set;
*/

Document.prototype.$__shouldModify = function(pathToMark, path, options, constructing, parts, schema, val, priorVal) {
if (options && options._skipMarkModified) {
if (options._skipMarkModified) {
return false;
}
if (this.$isNew) {
Expand Down Expand Up @@ -1732,6 +1733,7 @@ Document.prototype.$__setValue = function(path, val) {

Document.prototype.get = function(path, type, options) {
let adhoc;
options = options || {};
if (type) {
adhoc = this.$__schema.interpretAsType(path, type, this.$__schema.options);
}
Expand Down Expand Up @@ -1778,9 +1780,9 @@ Document.prototype.get = function(path, type, options) {
obj = adhoc.cast(obj);
}

if (schema != null && options && options.getters !== false) {
if (schema != null && options.getters !== false) {
obj = schema.applyGetters(obj, this);
} else if (this.$__schema.nested[path] && options && options.virtuals) {
} else if (this.$__schema.nested[path] && options.virtuals) {
// Might need to apply virtuals if this is a nested path
return applyVirtuals(this, utils.clone(obj) || {}, { path: path });
}
Expand Down Expand Up @@ -1978,6 +1980,8 @@ function _isEmpty(v) {
*/

Document.prototype.modifiedPaths = function(options) {
options = options || {};

const directModifiedPaths = Object.keys(this.$__.activePaths.states.modify);
const result = new Set();

Expand All @@ -1994,7 +1998,7 @@ Document.prototype.modifiedPaths = function(options) {
result.add(parts[j]);
}

if (!options || !options.includeChildren) {
if (!options.includeChildren) {
continue;
}

Expand Down

0 comments on commit 905d9bf

Please sign in to comment.