From c4b7378883329eb29778b5732d8430f26ddc8379 Mon Sep 17 00:00:00 2001 From: Nikolay Edigaryev Date: Fri, 6 Feb 2026 18:16:58 +0100 Subject: [PATCH] controller(listVMs): avoid copy of each element when filtering (#401) * controller(listVMs): avoid copy of each element when filtering * Explain the change --- internal/controller/api_vms.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/controller/api_vms.go b/internal/controller/api_vms.go index 5c7a387..58c07ab 100644 --- a/internal/controller/api_vms.go +++ b/internal/controller/api_vms.go @@ -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)