From 04a2a5fb24b1086c8130203451c2836f196e92c6 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Sat, 18 Sep 2021 02:39:45 +1200 Subject: [PATCH] perf: directly request enumerable keys so that they don't need to then be filtered --- src/utils.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index df1fd40b..dfa613b7 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -55,19 +55,20 @@ export function getObjectType(object: unknown): ObjectType { export function getKeys( objects: Readonly> ): Set { - return objects.reduce>((mutableCarry, object) => { - // eslint-disable-next-line functional/no-loop-statement -- using a loop here is more efficient. + const keys = new Set(); + + /* eslint-disable functional/no-loop-statement -- using a loop here is more efficient. */ + for (const object of objects) { for (const key of [ - ...Object.getOwnPropertyNames(object), + ...Object.keys(object), ...Object.getOwnPropertySymbols(object), - ].filter((property) => - Object.prototype.propertyIsEnumerable.call(object, property) - )) { - mutableCarry.add(key); + ]) { + keys.add(key); } + } + /* eslint-enable functional/no-loop-statement */ - return mutableCarry; - }, new Set()); + return keys; } /**