Skip to content

Commit

Permalink
refactor: reduce number of array accesses
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Oct 28, 2017
1 parent 85821d9 commit 9c709e1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/services/updateValidators.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = function(query, schema, castedDoc, options) {
var hasDollarUpdate = false;
var modified = {};
var currentUpdate;
var key;

for (var i = 0; i < numKeys; ++i) {
if (keys[i].charAt(0) === '$') {
Expand All @@ -55,10 +56,11 @@ module.exports = function(query, schema, castedDoc, options) {
for (var j = 0; j < numPaths; ++j) {
var updatedPath = paths[j].replace('.$.', '.0.');
updatedPath = updatedPath.replace(/\.\$$/, '.0');
if (keys[i] === '$set' || keys[i] === '$setOnInsert' ||
keys[i] === '$pull' || keys[i] === '$pullAll') {
key = keys[i];
if (keys === '$set' || keys === '$setOnInsert' ||
keys === '$pull' || keys === '$pullAll') {
updatedValues[updatedPath] = flat[paths[j]];
} else if (keys[i] === '$unset') {
} else if (key === '$unset') {
updatedValues[updatedPath] = undefined;
}
updatedKeys[updatedPath] = true;
Expand Down

0 comments on commit 9c709e1

Please sign in to comment.