Skip to content

Commit

Permalink
Use strings.Cut in parseCPURange
Browse files Browse the repository at this point in the history
  • Loading branch information
tklauser committed Nov 30, 2023
1 parent 7080285 commit 32d39fd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
build-and-test:
strategy:
matrix:
go-version: ['1.19', '1.20', '1.21']
go-version: ['1.18', '1.20', '1.21']
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/tklauser/numcpus

go 1.13
go 1.18

require golang.org/x/sys v0.15.0
8 changes: 4 additions & 4 deletions numcpus_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ func parseCPURange(cpus string) (int, error) {
if len(cpuRange) == 0 {
continue
}
rangeOp := strings.SplitN(cpuRange, "-", 2)
first, err := strconv.ParseUint(rangeOp[0], 10, 32)
from, to, found := strings.Cut(cpuRange, "-")
first, err := strconv.ParseUint(from, 10, 32)
if err != nil {
return 0, err
}
if len(rangeOp) == 1 {
if !found {
n++
continue
}
last, err := strconv.ParseUint(rangeOp[1], 10, 32)
last, err := strconv.ParseUint(to, 10, 32)
if err != nil {
return 0, err
}
Expand Down

0 comments on commit 32d39fd

Please sign in to comment.