Skip to content

Commit e9855bd

Browse files
committed
libct/cg/fscommon: use strings.Cut in RDMA parser
Using strings.Cut (added in Go 1.18, see [1]) results in faster and cleaner code with less allocations (as we're not using a slice). Also, use switch in parseRdmaKV. [1]: golang/go#46336 Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 930cd49 commit e9855bd

File tree

1 file changed

+5
-6
lines changed
  • libcontainer/cgroups/fscommon

1 file changed

+5
-6
lines changed

libcontainer/cgroups/fscommon/rdma.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ import (
1717
func parseRdmaKV(raw string, entry *cgroups.RdmaEntry) error {
1818
var value uint32
1919

20-
parts := strings.SplitN(raw, "=", 3)
20+
k, v, ok := strings.Cut(raw, "=")
2121

22-
if len(parts) != 2 {
22+
if !ok {
2323
return errors.New("Unable to parse RDMA entry")
2424
}
2525

26-
k, v := parts[0], parts[1]
27-
2826
if v == "max" {
2927
value = math.MaxUint32
3028
} else {
@@ -34,9 +32,10 @@ func parseRdmaKV(raw string, entry *cgroups.RdmaEntry) error {
3432
}
3533
value = uint32(val64)
3634
}
37-
if k == "hca_handle" {
35+
switch k {
36+
case "hca_handle":
3837
entry.HcaHandles = value
39-
} else if k == "hca_object" {
38+
case "hca_object":
4039
entry.HcaObjects = value
4140
}
4241

0 commit comments

Comments
 (0)