From 9c8403cc939894bf37198e5ea4e63881a84e7f21 Mon Sep 17 00:00:00 2001 From: Ben Elliott <4996462+benelliott@users.noreply.github.com> Date: Wed, 26 May 2021 10:29:20 +0100 Subject: [PATCH] perf: isPlainObject: add quick comparison between input and `Object` to short-circuit taxing `Function.toString` invocations --- src/utils/common.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils/common.ts b/src/utils/common.ts index 58de2b6f..f41ee0aa 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -46,6 +46,10 @@ export function isPlainObject(value: any): boolean { } const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor + + if (Ctor === Object) + return true + return ( typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString