Skip to content

Commit

Permalink
lxc/file: replace fmt.Sprintf (slow) by strconv.FormatInt
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Deziel <[email protected]>
  • Loading branch information
simondeziel committed Jan 21, 2025
1 parent cf0e333 commit 2211e97
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions lxc/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (c *cmdFileCreate) run(cmd *cobra.Command, args []string) error {
Length: contentLength,
Handler: func(percent int64, speed int64) {
progress.UpdateProgress(ioprogress.ProgressData{
Text: fmt.Sprintf("%d%% (%s/s)", percent, units.GetByteSizeString(speed, 2)),
Text: strconv.FormatInt(percent, 10) + "% (" + units.GetByteSizeString(speed, 2) + "/s)",
})
},
},
Expand Down Expand Up @@ -661,9 +661,8 @@ func (c *cmdFilePull) run(cmd *cobra.Command, args []string) error {
}

progress.UpdateProgress(ioprogress.ProgressData{
Text: fmt.Sprintf("%s (%s/s)",
units.GetByteSizeString(bytesReceived, 2),
units.GetByteSizeString(speed, 2))})
Text: units.GetByteSizeString(bytesReceived, 2) + " (" + units.GetByteSizeString(speed, 2) + "/s)",
})
},
},
}
Expand Down Expand Up @@ -950,7 +949,7 @@ func (c *cmdFilePush) run(cmd *cobra.Command, args []string) error {
Length: fstat.Size(),
Handler: func(percent int64, speed int64) {
progress.UpdateProgress(ioprogress.ProgressData{
Text: fmt.Sprintf("%d%% (%s/s)", percent, units.GetByteSizeString(speed, 2)),
Text: strconv.FormatInt(percent, 10) + "% (" + units.GetByteSizeString(speed, 2) + "/s)",
})
},
},
Expand Down Expand Up @@ -1015,9 +1014,8 @@ func (c *cmdFile) recursivePullFile(d lxd.InstanceServer, inst string, p string,
Tracker: &ioprogress.ProgressTracker{
Handler: func(bytesReceived int64, speed int64) {
progress.UpdateProgress(ioprogress.ProgressData{
Text: fmt.Sprintf("%s (%s/s)",
units.GetByteSizeString(bytesReceived, 2),
units.GetByteSizeString(speed, 2))})
Text: units.GetByteSizeString(bytesReceived, 2) + " (" + units.GetByteSizeString(speed, 2) + "/s)",
})
},
},
}
Expand Down Expand Up @@ -1127,8 +1125,8 @@ func (c *cmdFile) recursivePushFile(d lxd.InstanceServer, inst string, source st
Length: contentLength,
Handler: func(percent int64, speed int64) {
progress.UpdateProgress(ioprogress.ProgressData{
Text: fmt.Sprintf("%d%% (%s/s)", percent,
units.GetByteSizeString(speed, 2))})
Text: strconv.FormatInt(percent, 10) + "% (" + units.GetByteSizeString(speed, 2) + "/s)",
})
},
},
}, args.Content)
Expand Down

0 comments on commit 2211e97

Please sign in to comment.