Skip to content

Commit d36498e

Browse files
authored
refactor: strings.SplitSeq is introduced since Go 1.24.0 and ranging over SplitSeq is more efficient (#1239)
Signed-off-by: Shouren Yang <yangshouren@gmail.com>
1 parent 2320018 commit d36498e

File tree

7 files changed

+10
-15
lines changed

7 files changed

+10
-15
lines changed

pkg/device-plugin/nvidiadevice/nvinternal/plugin/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func GetIndexAndTypeFromUUID(uuid string) (string, int) {
120120

121121
func GetMigUUIDFromSmiOutput(output string, uuid string, idx int) string {
122122
migmode := false
123-
for _, val := range strings.Split(output, "\n") {
123+
for val := range strings.SplitSeq(output, "\n") {
124124
if !strings.Contains(val, "MIG") && strings.Contains(val, uuid) {
125125
migmode = true
126126
continue

pkg/device-plugin/nvidiadevice/nvinternal/rm/health.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func getAdditionalXids(input string) []uint64 {
226226
}
227227

228228
var additionalXids []uint64
229-
for _, additionalXid := range strings.Split(input, ",") {
229+
for additionalXid := range strings.SplitSeq(input, ",") {
230230
trimmed := strings.TrimSpace(additionalXid)
231231
if trimmed == "" {
232232
continue

pkg/device/enflame/device.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@ func (dev *EnflameDevices) checkUUID(annos map[string]string, d util.DeviceUsage
180180
if ok {
181181
klog.V(5).Infof("check uuid for Iluvatar user uuid [%s], device id is %s", userUUID, d.ID)
182182
// use , symbol to connect multiple uuid
183-
userUUIDs := strings.Split(userUUID, ",")
184-
for _, uuid := range userUUIDs {
183+
for uuid := range strings.SplitSeq(userUUID, ",") {
185184
if d.ID == uuid {
186185
return true
187186
}
@@ -193,8 +192,7 @@ func (dev *EnflameDevices) checkUUID(annos map[string]string, d util.DeviceUsage
193192
if ok {
194193
klog.V(5).Infof("check uuid for Iluvatar not user uuid [%s], device id is %s", noUserUUID, d.ID)
195194
// use , symbol to connect multiple uuid
196-
noUserUUIDs := strings.Split(noUserUUID, ",")
197-
for _, uuid := range noUserUUIDs {
195+
for uuid := range strings.SplitSeq(noUserUUID, ",") {
198196
if d.ID == uuid {
199197
return false
200198
}

pkg/device/hygon/device.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func checkDCUtype(annos map[string]string, cardtype string) bool {
9595
return true
9696
}
9797
} else {
98-
for _, val := range strings.Split(inuse, ",") {
98+
for val := range strings.SplitSeq(inuse, ",") {
9999
if strings.Contains(strings.ToUpper(cardtype), strings.ToUpper(val)) {
100100
return true
101101
}
@@ -109,7 +109,7 @@ func checkDCUtype(annos map[string]string, cardtype string) bool {
109109
return false
110110
}
111111
} else {
112-
for _, val := range strings.Split(nouse, ",") {
112+
for val := range strings.SplitSeq(nouse, ",") {
113113
if strings.Contains(strings.ToUpper(cardtype), strings.ToUpper(val)) {
114114
return false
115115
}

pkg/device/kunlun/device.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,7 @@ func parseInterconnection() [][]int {
270270

271271
func parseInterconnection2() [][]int {
272272
var interconnection2 [][]int
273-
groups := strings.Split(InterGroupConnection2, ",")
274-
for _, group := range groups {
273+
for group := range strings.SplitSeq(InterGroupConnection2, ",") {
275274
values := strings.Split(group, "-")
276275
connect := make([]int, 4)
277276
for i, value := range values {
@@ -293,8 +292,7 @@ func interconnect(devices []*util.DeviceUsage, count int) []int {
293292
if val2.Used > 0 || val2.Index == val.Index {
294293
continue
295294
}
296-
pairs := strings.Split(InterGroupConnection, ",")
297-
for _, p := range pairs {
295+
for p := range strings.SplitSeq(InterGroupConnection, ",") {
298296
lw, _ := strconv.Atoi(strings.Split(p, "-")[0])
299297
rw, _ := strconv.Atoi(strings.Split(p, "-")[1])
300298
klog.V(5).InfoS("interconnect", "lw", lw, "rw", rw, "left device", val.Index, "right device", val2.Index)

pkg/scheduler/score_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3011,8 +3011,7 @@ func makeDevice(id string, numa int, Type string, used, count, totalmem, usedmem
30113011
// This function parses the string and returns a map where the key is the reason and the value is the corresponding count.
30123012
func convertReasonToMap(reason string) map[string]int {
30133013
var reasonMap map[string]int
3014-
reasonSlice := strings.Split(reason, ", ")
3015-
for _, r := range reasonSlice {
3014+
for r := range strings.SplitSeq(reason, ", ") {
30163015
parts := strings.SplitN(r, " ", 2)
30173016
if len(parts) != 2 {
30183017
continue

pkg/util/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ func DecodePodDevices(checklist map[string]string, annos map[string]string) (Pod
333333
continue
334334
}
335335
pd[devID] = make(PodSingleDevice, 0)
336-
for _, s := range strings.Split(str, OnePodMultiContainerSplitSymbol) {
336+
for s := range strings.SplitSeq(str, OnePodMultiContainerSplitSymbol) {
337337
cd, err := DecodeContainerDevices(s)
338338
if err != nil {
339339
return PodDevices{}, nil

0 commit comments

Comments
 (0)