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:
Nikolay Edigaryev 2026-02-06 18:16:58 +01:00 committed by GitHub
parent f3b4eb42ca
commit c4b7378883
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 3 deletions

View File

@ -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)