From f1d220020b92666c071210a7f84fd5537798db4e Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Tue, 30 Jul 2024 14:52:57 +0200 Subject: [PATCH] fix: improve perf of isActionOfType by limiting calls to the includes --- src/libs/ReportActionsUtils.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 8e9926648c2c..10b6de73b136 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -189,7 +189,14 @@ function isActionOfType( ): action is { [K in keyof T]: ReportAction; }[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(reportAction: OnyxInputOrEntry>): OriginalMessage | undefined {