Merge pull request #45421 from allencloud/change-to-use-make-slice-to-store-objects
Automatic merge from submit-queue use make slice to store objects to improve efficiency Signed-off-by: allencloud <allen.sun@daocloud.io> **What this PR does / why we need it**: we we know the slice length in advance, I think we had better use make to create the specified length of slice. This will improve some kind of performance. Since if we create a slice with []type{}, we did not know how much space runtime should reserve, since slice implementation should be continuous in memory. While when we make a slice with specified length, runtime would reserve a continuous memory space which will not result in slice movement in case of current space is not enough. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # NONE **Special notes for your reviewer**: NONE **Release note**: ```release-note NONE ```
This commit is contained in:
		@@ -342,7 +342,7 @@ func (ds *dockerService) ContainerStatus(containerID string) (*runtimeapi.Contai
 | 
				
			|||||||
	imageID := toPullableImageID(r.Image, ir)
 | 
						imageID := toPullableImageID(r.Image, ir)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Convert the mounts.
 | 
						// Convert the mounts.
 | 
				
			||||||
	mounts := []*runtimeapi.Mount{}
 | 
						mounts := make([]*runtimeapi.Mount, 0, len(r.Mounts))
 | 
				
			||||||
	for i := range r.Mounts {
 | 
						for i := range r.Mounts {
 | 
				
			||||||
		m := r.Mounts[i]
 | 
							m := r.Mounts[i]
 | 
				
			||||||
		readonly := !m.RW
 | 
							readonly := !m.RW
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -43,7 +43,7 @@ func (ds *dockerService) ListImages(filter *runtimeapi.ImageFilter) ([]*runtimea
 | 
				
			|||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result := []*runtimeapi.Image{}
 | 
						result := make([]*runtimeapi.Image, 0, len(images))
 | 
				
			||||||
	for _, i := range images {
 | 
						for _, i := range images {
 | 
				
			||||||
		apiImage, err := imageToRuntimeAPIImage(&i)
 | 
							apiImage, err := imageToRuntimeAPIImage(&i)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -187,7 +187,7 @@ func (ds *dockerService) ListLegacyPodSandbox(filter *runtimeapi.PodSandboxFilte
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Convert docker containers to runtime api sandboxes.
 | 
						// Convert docker containers to runtime api sandboxes.
 | 
				
			||||||
	result := []*runtimeapi.PodSandbox{}
 | 
						result := make([]*runtimeapi.PodSandbox, 0, len(containers))
 | 
				
			||||||
	for i := range containers {
 | 
						for i := range containers {
 | 
				
			||||||
		c := containers[i]
 | 
							c := containers[i]
 | 
				
			||||||
		// Skip new containers with containerTypeLabelKey label.
 | 
							// Skip new containers with containerTypeLabelKey label.
 | 
				
			||||||
@@ -242,7 +242,7 @@ func (ds *dockerService) ListLegacyContainers(filter *runtimeapi.ContainerFilter
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Convert docker to runtime api containers.
 | 
						// Convert docker to runtime api containers.
 | 
				
			||||||
	result := []*runtimeapi.Container{}
 | 
						result := make([]*runtimeapi.Container, 0, len(containers))
 | 
				
			||||||
	for i := range containers {
 | 
						for i := range containers {
 | 
				
			||||||
		c := containers[i]
 | 
							c := containers[i]
 | 
				
			||||||
		// Skip new containers with containerTypeLabelKey label.
 | 
							// Skip new containers with containerTypeLabelKey label.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -332,7 +332,7 @@ func (ds *dockerService) GetPodPortMappings(podSandboxID string) ([]*hostport.Po
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	portMappings := []*hostport.PortMapping{}
 | 
						portMappings := make([]*hostport.PortMapping, 0, len(checkpoint.Data.PortMappings))
 | 
				
			||||||
	for _, pm := range checkpoint.Data.PortMappings {
 | 
						for _, pm := range checkpoint.Data.PortMappings {
 | 
				
			||||||
		proto := toAPIProtocol(*pm.Protocol)
 | 
							proto := toAPIProtocol(*pm.Protocol)
 | 
				
			||||||
		portMappings = append(portMappings, &hostport.PortMapping{
 | 
							portMappings = append(portMappings, &hostport.PortMapping{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -129,7 +129,8 @@ func extractLabels(input map[string]string) (map[string]string, map[string]strin
 | 
				
			|||||||
// '<HostPath>:<ContainerPath>:ro', if the path is read only, or
 | 
					// '<HostPath>:<ContainerPath>:ro', if the path is read only, or
 | 
				
			||||||
// '<HostPath>:<ContainerPath>:Z', if the volume requires SELinux
 | 
					// '<HostPath>:<ContainerPath>:Z', if the volume requires SELinux
 | 
				
			||||||
// relabeling and the pod provides an SELinux label
 | 
					// relabeling and the pod provides an SELinux label
 | 
				
			||||||
func generateMountBindings(mounts []*runtimeapi.Mount) (result []string) {
 | 
					func generateMountBindings(mounts []*runtimeapi.Mount) []string {
 | 
				
			||||||
 | 
						result := make([]string, 0, len(mounts))
 | 
				
			||||||
	for _, m := range mounts {
 | 
						for _, m := range mounts {
 | 
				
			||||||
		bind := fmt.Sprintf("%s:%s", m.HostPath, m.ContainerPath)
 | 
							bind := fmt.Sprintf("%s:%s", m.HostPath, m.ContainerPath)
 | 
				
			||||||
		readOnly := m.Readonly
 | 
							readOnly := m.Readonly
 | 
				
			||||||
@@ -149,7 +150,7 @@ func generateMountBindings(mounts []*runtimeapi.Mount) (result []string) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		result = append(result, bind)
 | 
							result = append(result, bind)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return
 | 
						return result
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func makePortsAndBindings(pm []*runtimeapi.PortMapping) (map[dockernat.Port]struct{}, map[dockernat.Port][]dockernat.PortBinding) {
 | 
					func makePortsAndBindings(pm []*runtimeapi.PortMapping) (map[dockernat.Port]struct{}, map[dockernat.Port][]dockernat.PortBinding) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user