From 8ead26657e49afbd1bf9ff9009d6c71f97c37c7e Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Sat, 27 Apr 2024 18:05:21 -0400 Subject: [PATCH] perf(document): add fast path for applying non-nested virtuals to JSON Re: #14394 --- lib/document.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/document.js b/lib/document.js index b5f949b2fa5..8a9149ebbe9 100644 --- a/lib/document.js +++ b/lib/document.js @@ -4130,6 +4130,14 @@ function applyVirtuals(self, json, options, toObjectOptions) { } assignPath = path.substring(options.path.length + 1); } + if (assignPath.indexOf('.') === -1 && assignPath === path) { + v = clone(self.get(path, options ? { ...options, noDottedPath: true } : { noDottedPath: true })); + if (v === void 0) { + continue; + } + json[assignPath] = v; + continue; + } const parts = assignPath.split('.'); v = clone(self.get(path), options); if (v === void 0) {