From 305d5b285f4be92e11b1cfa042b01a54b8d58ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Taylor?= Date: Fri, 1 Mar 2024 20:18:47 +0100 Subject: [PATCH] chore: optimize batches with one item (#875) Signed-off-by: Andres Taylor --- commands.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/commands.go b/commands.go index 7b139b8858..164dad21ad 100644 --- a/commands.go +++ b/commands.go @@ -20,11 +20,15 @@ func Batch(cmds ...Cmd) Cmd { } validCmds = append(validCmds, c) } - if len(validCmds) == 0 { + switch len(validCmds) { + case 0: return nil - } - return func() Msg { - return BatchMsg(validCmds) + case 1: + return validCmds[0] + default: + return func() Msg { + return BatchMsg(validCmds) + } } }