Skip to content

Commit

Permalink
libct/cg/fscommon: use strings.Cut in RDMA parser
Browse files Browse the repository at this point in the history
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 <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Dec 5, 2024
1 parent a4b2701 commit 75cbfa3
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions libcontainer/cgroups/fscommon/rdma.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ import (
func parseRdmaKV(raw string, entry *cgroups.RdmaEntry) error {
var value uint32

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

if len(parts) != 2 {
if !ok {
return errors.New("Unable to parse RDMA entry")
}

k, v := parts[0], parts[1]

if v == "max" {
value = math.MaxUint32
} else {
Expand All @@ -34,9 +32,10 @@ func parseRdmaKV(raw string, entry *cgroups.RdmaEntry) error {
}
value = uint32(val64)
}
if k == "hca_handle" {
switch k {
case "hca_handle":
entry.HcaHandles = value
} else if k == "hca_object" {
case "hca_object":
entry.HcaObjects = value
}

Expand Down

0 comments on commit 75cbfa3

Please sign in to comment.