Skip to content

Commit

Permalink
lxd/project/project: simplify string concatenation operations
Browse files Browse the repository at this point in the history
`fmt.Sprintf` being much slower it should be kept for when it is really needed.
It's slowness comes from using reflection under the hood making it the slowest
of the `fmt.Sprint*` functions.

Signed-off-by: Simon Deziel <[email protected]>
  • Loading branch information
simondeziel committed Nov 18, 2024
1 parent 7704860 commit 90b0281
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lxd/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const separator = "_"
// Instance adds the "<project>_" prefix to instance name when the given project name is not "default".
func Instance(projectName string, instanceName string) string {
if projectName != api.ProjectDefaultName {
return fmt.Sprintf("%s%s%s", projectName, separator, instanceName)
return projectName+separator+instanceName
}

return instanceName
Expand All @@ -27,7 +27,7 @@ func Instance(projectName string, instanceName string) string {
// DNS adds ".<project>" as a suffix to instance name when the given project name is not "default".
func DNS(projectName string, instanceName string) string {
if projectName != api.ProjectDefaultName {
return fmt.Sprintf("%s.%s", instanceName, projectName)
return instanceName+"."+projectName
}

return instanceName
Expand All @@ -52,7 +52,7 @@ func InstanceParts(projectInstanceName string) (projectName string, instanceName

// StorageVolume adds the "<project>_prefix" to the storage volume name. Even if the project name is "default".
func StorageVolume(projectName string, storageVolumeName string) string {
return fmt.Sprintf("%s%s%s", projectName, separator, storageVolumeName)
return projectName+separator+storageVolumeName
}

// StorageVolumeParts takes a project prefixed storage volume name and returns the project and storage volume
Expand Down

0 comments on commit 90b0281

Please sign in to comment.