From 9cd8326bb2bbc66bbbd3d96c4825693520f9a43e Mon Sep 17 00:00:00 2001 From: Ben Ye Date: Sun, 8 Aug 2021 22:45:40 -0700 Subject: [PATCH] cleanup: allocate slice with known size As the input capabilities size is known, it is better to allocate slice with a specified size. Signed-off-by: Ben Ye --- internal/csi-common/driver.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/csi-common/driver.go b/internal/csi-common/driver.go index d15107054..670e4ca3f 100644 --- a/internal/csi-common/driver.go +++ b/internal/csi-common/driver.go @@ -88,7 +88,7 @@ func (d *CSIDriver) ValidateControllerServiceRequest(c csi.ControllerServiceCapa // AddControllerServiceCapabilities stores the controller capabilities // in driver object. func (d *CSIDriver) AddControllerServiceCapabilities(cl []csi.ControllerServiceCapability_RPC_Type) { - var csc []*csi.ControllerServiceCapability + csc := make([]*csi.ControllerServiceCapability, 0, len(cl)) for _, c := range cl { util.DefaultLog("Enabling controller service capability: %v", c.String()) @@ -101,7 +101,7 @@ func (d *CSIDriver) AddControllerServiceCapabilities(cl []csi.ControllerServiceC // AddVolumeCapabilityAccessModes stores volume access modes. func (d *CSIDriver) AddVolumeCapabilityAccessModes( vc []csi.VolumeCapability_AccessMode_Mode) []*csi.VolumeCapability_AccessMode { - var vca []*csi.VolumeCapability_AccessMode + vca := make([]*csi.VolumeCapability_AccessMode, 0, len(vc)) for _, c := range vc { util.DefaultLog("Enabling volume access mode: %v", c.String()) vca = append(vca, NewVolumeCapabilityAccessMode(c))