runtime: Optimize the way slice created

Initialize and assign a value, reducing one append operation

Fixes: #2264

Signed-off-by: Binbin Zhang <binbin36520@gmail.com>
This commit is contained in:
Binbin Zhang 2021-08-28 04:15:59 +08:00
parent fb583780f6
commit ff37f5c798
2 changed files with 2 additions and 7 deletions

View File

@ -742,11 +742,7 @@ func (clh *cloudHypervisor) check() error {
}
func (clh *cloudHypervisor) getPids() []int {
var pids []int
pids = append(pids, clh.state.PID)
return pids
return []int{clh.state.PID}
}
func (clh *cloudHypervisor) getVirtioFsPid() *int {

View File

@ -2280,8 +2280,7 @@ func (q *qemu) getPids() []int {
return []int{0}
}
var pids []int
pids = append(pids, pid)
pids := []int{pid}
if q.state.VirtiofsdPid != 0 {
pids = append(pids, q.state.VirtiofsdPid)
}