controller(listVMs): avoid copy of each element when filtering (#401)
* controller(listVMs): avoid copy of each element when filtering * Explain the change
This commit is contained in:
parent
f3b4eb42ca
commit
c4b7378883
|
|
@ -349,13 +349,14 @@ func (controller *Controller) listVMs(ctx *gin.Context) responder.Responder {
|
|||
vms := []v1.VM{}
|
||||
|
||||
Outer:
|
||||
for _, vm := range allVMs {
|
||||
// Use index-based loop to avoid per-iteration copies of v1.VM
|
||||
for i := range allVMs {
|
||||
for _, filter := range filters {
|
||||
if !vm.Match(filter) {
|
||||
if !allVMs[i].Match(filter) {
|
||||
continue Outer
|
||||
}
|
||||
}
|
||||
vms = append(vms, vm)
|
||||
vms = append(vms, allVMs[i])
|
||||
}
|
||||
|
||||
return responder.JSON(http.StatusOK, vms)
|
||||
|
|
|
|||
Loading…
Reference in New Issue