replace some basic uses of fmt.Sprintf()
Really tiny gains here, and doesn't significantly impact readability:
    BenchmarkSprintf
    BenchmarkSprintf-10    11528700     91.59 ns/op   32 B/op  1 allocs/op
    BenchmarkConcat
    BenchmarkConcat-10    100000000     11.76 ns/op    0 B/op  0 allocs/op
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
			
			
This commit is contained in:
		| @@ -185,7 +185,7 @@ func NewWithConn(conn *grpc.ClientConn, opts ...ClientOpt) (*Client, error) { | |||||||
| 	c := &Client{ | 	c := &Client{ | ||||||
| 		defaultns: copts.defaultns, | 		defaultns: copts.defaultns, | ||||||
| 		conn:      conn, | 		conn:      conn, | ||||||
| 		runtime:   fmt.Sprintf("%s.%s", plugin.RuntimePlugin, runtime.GOOS), | 		runtime:   plugin.RuntimePlugin.String() + "." + runtime.GOOS, | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if copts.defaultPlatform != nil { | 	if copts.defaultPlatform != nil { | ||||||
|   | |||||||
| @@ -177,7 +177,7 @@ func TestContainerStart(t *testing.T) { | |||||||
| } | } | ||||||
|  |  | ||||||
| func readShimPath(taskID string) (string, error) { | func readShimPath(taskID string) (string, error) { | ||||||
| 	runtime := fmt.Sprintf("%s.%s", plugin.RuntimePluginV2, "task") | 	runtime := plugin.RuntimePluginV2.String() + ".task" | ||||||
| 	shimBinaryNamePath := filepath.Join(defaultState, runtime, testNamespace, taskID, "shim-binary-path") | 	shimBinaryNamePath := filepath.Join(defaultState, runtime, testNamespace, taskID, "shim-binary-path") | ||||||
|  |  | ||||||
| 	shimPath, err := os.ReadFile(shimBinaryNamePath) | 	shimPath, err := os.ReadFile(shimBinaryNamePath) | ||||||
|   | |||||||
| @@ -350,7 +350,7 @@ func (c *criService) register(s *grpc.Server) error { | |||||||
| // imageFSPath returns containerd image filesystem path. | // imageFSPath returns containerd image filesystem path. | ||||||
| // Note that if containerd changes directory layout, we also needs to change this. | // Note that if containerd changes directory layout, we also needs to change this. | ||||||
| func imageFSPath(rootDir, snapshotter string) string { | func imageFSPath(rootDir, snapshotter string) string { | ||||||
| 	return filepath.Join(rootDir, fmt.Sprintf("%s.%s", plugin.SnapshotPlugin, snapshotter)) | 	return filepath.Join(rootDir, plugin.SnapshotPlugin.String()+"."+snapshotter) | ||||||
| } | } | ||||||
|  |  | ||||||
| func loadOCISpec(filename string) (*oci.Spec, error) { | func loadOCISpec(filename string) (*oci.Spec, error) { | ||||||
|   | |||||||
| @@ -332,7 +332,7 @@ func (c *criService) register(s *grpc.Server) error { | |||||||
| // imageFSPath returns containerd image filesystem path. | // imageFSPath returns containerd image filesystem path. | ||||||
| // Note that if containerd changes directory layout, we also needs to change this. | // Note that if containerd changes directory layout, we also needs to change this. | ||||||
| func imageFSPath(rootDir, snapshotter string) string { | func imageFSPath(rootDir, snapshotter string) string { | ||||||
| 	return filepath.Join(rootDir, fmt.Sprintf("%s.%s", plugin.SnapshotPlugin, snapshotter)) | 	return filepath.Join(rootDir, plugin.SnapshotPlugin.String()+"."+snapshotter) | ||||||
| } | } | ||||||
|  |  | ||||||
| func loadOCISpec(filename string) (*oci.Spec, error) { | func loadOCISpec(filename string) (*oci.Spec, error) { | ||||||
|   | |||||||
| @@ -130,7 +130,7 @@ func (r *Registration) Init(ic *InitContext) *Plugin { | |||||||
|  |  | ||||||
| // URI returns the full plugin URI | // URI returns the full plugin URI | ||||||
| func (r *Registration) URI() string { | func (r *Registration) URI() string { | ||||||
| 	return fmt.Sprintf("%s.%s", r.Type, r.ID) | 	return r.Type.String() + "." + r.ID | ||||||
| } | } | ||||||
|  |  | ||||||
| var register = struct { | var register = struct { | ||||||
|   | |||||||
| @@ -103,7 +103,7 @@ func appendDistributionSourceLabel(originLabel, repo string) string { | |||||||
| } | } | ||||||
|  |  | ||||||
| func distributionSourceLabelKey(source string) string { | func distributionSourceLabelKey(source string) string { | ||||||
| 	return fmt.Sprintf("%s.%s", labels.LabelDistributionSource, source) | 	return labels.LabelDistributionSource + "." + source | ||||||
| } | } | ||||||
|  |  | ||||||
| // selectRepositoryMountCandidate will select the repo which has longest | // selectRepositoryMountCandidate will select the repo which has longest | ||||||
|   | |||||||
| @@ -177,7 +177,7 @@ type ShimManager struct { | |||||||
|  |  | ||||||
| // ID of the shim manager | // ID of the shim manager | ||||||
| func (m *ShimManager) ID() string { | func (m *ShimManager) ID() string { | ||||||
| 	return fmt.Sprintf("%s.%s", plugin.RuntimePluginV2, "shim") | 	return plugin.RuntimePluginV2.String() + ".shim" | ||||||
| } | } | ||||||
|  |  | ||||||
| // Start launches a new shim instance | // Start launches a new shim instance | ||||||
| @@ -413,7 +413,7 @@ func NewTaskManager(shims *ShimManager) *TaskManager { | |||||||
|  |  | ||||||
| // ID of the task manager | // ID of the task manager | ||||||
| func (m *TaskManager) ID() string { | func (m *TaskManager) ID() string { | ||||||
| 	return fmt.Sprintf("%s.%s", plugin.RuntimePluginV2, "task") | 	return plugin.RuntimePluginV2.String() + ".task" | ||||||
| } | } | ||||||
|  |  | ||||||
| // Create launches new shim instance and creates new task | // Create launches new shim instance and creates new task | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								task.go
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								task.go
									
									
									
									
									
								
							| @@ -311,7 +311,7 @@ func (t *task) Delete(ctx context.Context, opts ...ProcessDeleteOpts) (*ExitStat | |||||||
| 	switch status.Status { | 	switch status.Status { | ||||||
| 	case Stopped, Unknown, "": | 	case Stopped, Unknown, "": | ||||||
| 	case Created: | 	case Created: | ||||||
| 		if t.client.runtime == fmt.Sprintf("%s.%s", plugin.RuntimePlugin, "windows") { | 		if t.client.runtime == plugin.RuntimePlugin.String()+".windows" { | ||||||
| 			// On windows Created is akin to Stopped | 			// On windows Created is akin to Stopped | ||||||
| 			break | 			break | ||||||
| 		} | 		} | ||||||
| @@ -328,7 +328,7 @@ func (t *task) Delete(ctx context.Context, opts ...ProcessDeleteOpts) (*ExitStat | |||||||
| 		// io.Wait locks for restored tasks on Windows unless we call | 		// io.Wait locks for restored tasks on Windows unless we call | ||||||
| 		// io.Close first (https://github.com/containerd/containerd/issues/5621) | 		// io.Close first (https://github.com/containerd/containerd/issues/5621) | ||||||
| 		// in other cases, preserve the contract and let IO finish before closing | 		// in other cases, preserve the contract and let IO finish before closing | ||||||
| 		if t.client.runtime == fmt.Sprintf("%s.%s", plugin.RuntimePlugin, "windows") { | 		if t.client.runtime == plugin.RuntimePlugin.String()+".windows" { | ||||||
| 			t.io.Close() | 			t.io.Close() | ||||||
| 		} | 		} | ||||||
| 		// io.Cancel is used to cancel the io goroutine while it is in | 		// io.Cancel is used to cancel the io goroutine while it is in | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Sebastiaan van Stijn
					Sebastiaan van Stijn