Fix: Loop can be simplified using slices.Contains

This commit is contained in:
Holger Obermaier
2026-02-10 09:47:02 +01:00
parent cca0d23efa
commit 0990035d63
3 changed files with 21 additions and 15 deletions

View File

@@ -11,6 +11,7 @@ import (
"encoding/json"
"errors"
"fmt"
"slices"
"time"
cclog "github.com/ClusterCockpit/cc-lib/v2/ccLogger"
@@ -87,22 +88,11 @@ func (m *RocmSmiCollector) Init(config json.RawMessage) error {
return err
}
exclDev := func(s string) bool {
skip_device := false
for _, excl := range m.config.ExcludeDevices {
if excl == s {
skip_device = true
break
}
}
return skip_device
}
m.devices = make([]RocmSmiCollectorDevice, 0)
for i := 0; i < numDevs; i++ {
str_i := fmt.Sprintf("%d", i)
if exclDev(str_i) {
if slices.Contains(m.config.ExcludeDevices, str_i) {
continue
}
device, ret := rocm_smi.DeviceGetHandleByIndex(i)
@@ -126,7 +116,7 @@ func (m *RocmSmiCollector) Init(config json.RawMessage) error {
pciInfo.Device,
pciInfo.Function)
if exclDev(pciId) {
if slices.Contains(m.config.ExcludeDevices, pciId) {
continue
}