Skip to content

Commit

Permalink
Merge pull request #46497 from callstack-internal/fix/perf-is-action-…
Browse files Browse the repository at this point in the history
…of-type

perf: improve perf of isActionOfType by limiting calls to includes
  • Loading branch information
aldo-expensify committed Aug 7, 2024
2 parents 2336ba8 + de7aec3 commit c73b1f8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,16 @@ function isActionOfType<T extends ReportActionName[]>(
): action is {
[K in keyof T]: ReportAction<T[K]>;
}[number] {
return actionNames.includes(action?.actionName as T[number]);
const actionName = action?.actionName as T[number];

// This is purely a performance optimization to limit the 'includes()' calls on Hermes
for (const i of actionNames) {
if (i === actionName) {
return true;
}
}

return false;
}

function getOriginalMessage<T extends ReportActionName>(reportAction: OnyxInputOrEntry<ReportAction<T>>): OriginalMessage<T> | undefined {
Expand Down

0 comments on commit c73b1f8

Please sign in to comment.