Skip to content

Commit 3e60145

Browse files
committed
perf(schema): remove unnecessary lookahead in numeric subpath check
1 parent 3a015f9 commit 3e60145

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
@@ -25,6 +25,8 @@ const utils = require('./utils');
2525
const validateRef = require('./helpers/populate/validateRef');
2626
const util = require('util');
2727

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

3032
const queryHooks = require('./helpers/query/applyQueryMiddleware').
@@ -1008,7 +1010,7 @@ Schema.prototype.path = function(path, obj) {
10081010
}
10091011

10101012
// subpaths?
1011-
return /\.\d+\.?.*$/.test(path)
1013+
return hasNumericSubpathRegex.test(path)
10121014
? getPositionalPath(this, path, cleanPath)
10131015
: undefined;
10141016
}

0 commit comments

Comments
 (0)