From 5afc5b9ab34f82702c8cd3a700c0f67fdfe4c86d Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Thu, 22 Feb 2018 15:25:37 -0800 Subject: [PATCH] perf(createWrapper): don't create wrapper if there are no hooks Re: Automattic/mongoose#6126 --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index ec0dd65..4815204 100644 --- a/index.js +++ b/index.js @@ -304,6 +304,10 @@ Kareem.prototype.wrap = function(name, fn, context, args, options) { Kareem.prototype.createWrapper = function(name, fn, context, options) { var _this = this; + if (this._pres[name] == null && this._posts[name] == null) { + // Fast path: if there's no hooks for this function, just return the function + return fn; + } return function() { var _context = context || this; var args = Array.prototype.slice.call(arguments);