From 3c312ae6b1d60d9f9b99cca9640d84c31321b833 Mon Sep 17 00:00:00 2001 From: Simon Deziel Date: Thu, 16 Jan 2025 13:24:08 -0500 Subject: [PATCH] lxc/auth: avoid fmt.Sprintf (slow) and avoid strings.Join twice for CSV Signed-off-by: Simon Deziel --- lxc/auth.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lxc/auth.go b/lxc/auth.go index b41f1a9c1330..732923f003a8 100644 --- a/lxc/auth.go +++ b/lxc/auth.go @@ -1594,10 +1594,12 @@ func (c *cmdPermissionList) run(cmd *cobra.Command, args []string) error { var rowsAssigned []string for k, v := range p.entitlementsAssigned { // Pretty format for tables. - assignedRow := fmt.Sprintf("%s ==> (%s)", k, strings.Join(v, ", ")) + var assignedRow string if c.flagFormat == cli.TableFormatCSV { // Machine readable format for CSV. - assignedRow = fmt.Sprintf("%s:(%s)", k, strings.Join(v, ",")) + assignedRow = k + ":(" + strings.Join(v, ",") + ")" + } else { + assignedRow = k + " ==> (" + strings.Join(v, ", ") + ")" } rowsAssigned = append(rowsAssigned, assignedRow)