Skip to content

Commit 74152c2

Browse files
committed
refactor: use 'slices.Backward' for backward slice loop
In Go 1.23 and later, `slices.Backward` returns an iterator that ranges over a slice from the last element to the first. This removes manual index handling and helps avoid off-by-one errors. Signed-off-by: Ryan Johnson <ryan.johnson@broadcom.com>
1 parent 95737fc commit 74152c2

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

builder/vmware/common/driver_parser.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"os"
1616
"reflect"
1717
"regexp"
18+
"slices"
1819
"sort"
1920
"strconv"
2021
"strings"
@@ -956,12 +957,12 @@ func createDeclaration(node pDeclaration) ConfigDeclaration {
956957
result.hostid = make([]pParameterClientMatch, 0)
957958

958959
// walk from globals to pDeclaration collecting all parameters
959-
for i := len(hierarchy) - 1; i >= 0; i-- {
960+
for i, h := range slices.Backward(hierarchy) {
960961
result.composites = append(result.composites, hierarchy[(len(hierarchy)-1)-i])
961962
result.id = append(result.id, hierarchy[(len(hierarchy)-1)-i].id)
962963

963964
// update configDeclaration parameters
964-
for _, p := range hierarchy[i].parameters {
965+
for _, p := range h.parameters {
965966
switch p := p.(type) {
966967
case pParameterOption:
967968
result.options[p.name] = p.value

0 commit comments

Comments
 (0)