Skip to content

Commit

Permalink
fix: improve perf of isActionOfType by limiting calls to the includes
Browse files Browse the repository at this point in the history
  • Loading branch information
adhorodyski committed Jul 30, 2024
1 parent 3418820 commit f1d2200
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,14 @@ 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
if (actionNames.length === 1) {
return actionNames[0] === actionName;
}

return actionNames.includes(actionName);
}

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

0 comments on commit f1d2200

Please sign in to comment.