Skip to content

Commit

Permalink
perf: directly request enumerable keys so that they don't need to the…
Browse files Browse the repository at this point in the history
…n be filtered
  • Loading branch information
RebeccaStevens committed Sep 17, 2021
1 parent b36f7bc commit 04a2a5f
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,20 @@ export function getObjectType(object: unknown): ObjectType {
export function getKeys(
objects: Readonly<ReadonlyArray<object>>
): Set<RecordProperty> {
return objects.reduce<Set<RecordProperty>>((mutableCarry, object) => {
// eslint-disable-next-line functional/no-loop-statement -- using a loop here is more efficient.
const keys = new Set<RecordProperty>();

/* 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<RecordProperty>());
return keys;
}

/**
Expand Down

0 comments on commit 04a2a5f

Please sign in to comment.