Skip to content

Commit 8e141d1

Browse files
committed
perf(schema): remove unnecessary lookahead in numeric subpath check
1 parent e182fe5 commit 8e141d1

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/schema.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const utils = require('./utils');
2424
const validateRef = require('./helpers/populate/validateRef');
2525
const util = require('util');
2626

27+
const hasNumericSubpathRegex = /\.\d+(\.|$)/;
28+
2729
let MongooseTypes;
2830

2931
const queryHooks = require('./helpers/query/applyQueryMiddleware').
@@ -973,7 +975,7 @@ Schema.prototype.path = function(path, obj) {
973975
}
974976

975977
// subpaths?
976-
return /\.\d+\.?.*$/.test(path)
978+
return hasNumericSubpathRegex.test(path)
977979
? getPositionalPath(this, path)
978980
: undefined;
979981
}

0 commit comments

Comments
 (0)