fix: avoid strings.SplitSeq allocations on Go 1.24 and test Go 1.24 and stable in CI
- commit
- 2c367cd215e821fd554d7cee0f2c4484c3eb7f1e
- author
- brice · · 2026-10-08 17:48 UTC
- parent
- 455c41e
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email - refs
- tag: v0.1.0
2 files · +13 -5
M .github/workflows/ci.yml +6 -1
| @@ -11,13 +11,18 @@ concurrency: | |||
| 11 | 11 | jobs: | |
| 12 | 12 | check: | |
| 13 | 13 | runs-on: ubuntu-latest | |
| 14 | + | strategy: | |
| 15 | + | matrix: | |
| 16 | + | # The oldest supported Go and the newest: allocation behaviour | |
| 17 | + | # differs between compiler versions. | |
| 18 | + | go: ['1.24', stable] | |
| 14 | 19 | steps: | |
| 15 | 20 | - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| 16 | 21 | with: | |
| 17 | 22 | persist-credentials: false | |
| 18 | 23 | - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7 | |
| 19 | 24 | with: | |
| 20 | - | go-version-file: go.mod | |
| 25 | + | go-version: ${{ matrix.go }} | |
| 21 | 26 | # dbus-daemon runs the integration tests against a private bus. | |
| 22 | 27 | - run: sudo apt-get update && sudo apt-get install -y --no-install-recommends dbus | |
| 23 | 28 | - run: test -z "$(gofmt -l .)" | |
| @@ -11,13 +11,18 @@ concurrency: | |||||
| 11 | jobs: | 11 | jobs: | ||
| 12 | check: | 12 | check: | ||
| 13 | runs-on: ubuntu-latest | 13 | runs-on: ubuntu-latest | ||
| 14 | + | strategy: | |||
| 15 | + | matrix: | |||
| 16 | + | # The oldest supported Go and the newest: allocation behaviour | |||
| 17 | + | # differs between compiler versions. | |||
| 18 | + | go: ['1.24', stable] | |||
| 14 | steps: | 19 | steps: | ||
| 15 | - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | 20 | - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| 16 | with: | 21 | with: | ||
| 17 | persist-credentials: false | 22 | persist-credentials: false | ||
| 18 | - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7 | 23 | - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7 | ||
| 19 | with: | 24 | with: | ||
| 20 | - | go-version-file: go.mod | 25 | + | go-version: ${{ matrix.go }} |
| 21 | # dbus-daemon runs the integration tests against a private bus. | 26 | # dbus-daemon runs the integration tests against a private bus. | ||
| 22 | - run: sudo apt-get update && sudo apt-get install -y --no-install-recommends dbus | 27 | - run: sudo apt-get update && sudo apt-get install -y --no-install-recommends dbus | ||
| 23 | - run: test -z "$(gofmt -l .)" | 28 | - run: test -z "$(gofmt -l .)" | ||
M wire.go +7 -4
| @@ -161,12 +161,14 @@ func validInterface(s string) bool { | |||
| 161 | 161 | if len(s) > 255 { | |
| 162 | 162 | return false | |
| 163 | 163 | } | |
| 164 | + | // strings.Cut, not SplitSeq: before Go 1.25 the iterator allocates. | |
| 164 | 165 | n := 0 | |
| 165 | - | for e := range strings.SplitSeq(s, ".") { | |
| 166 | + | for more := true; more; n++ { | |
| 167 | + | var e string | |
| 168 | + | e, s, more = strings.Cut(s, ".") | |
| 166 | 169 | if !validMember(e) { | |
| 167 | 170 | return false | |
| 168 | 171 | } | |
| 169 | - | n++ | |
| 170 | 172 | } | |
| 171 | 173 | return n >= 2 | |
| 172 | 174 | } | |
| @@ -182,7 +184,9 @@ func validBusName(s string) bool { | |||
| 182 | 184 | s = s[1:] | |
| 183 | 185 | } | |
| 184 | 186 | n := 0 | |
| 185 | - | for e := range strings.SplitSeq(s, ".") { | |
| 187 | + | for more := true; more; n++ { | |
| 188 | + | var e string | |
| 189 | + | e, s, more = strings.Cut(s, ".") | |
| 186 | 190 | if e == "" || !unique && e[0] >= '0' && e[0] <= '9' { | |
| 187 | 191 | return false | |
| 188 | 192 | } | |
| @@ -191,7 +195,6 @@ func validBusName(s string) bool { | |||
| 191 | 195 | return false | |
| 192 | 196 | } | |
| 193 | 197 | } | |
| 194 | - | n++ | |
| 195 | 198 | } | |
| 196 | 199 | return n >= 2 | |
| 197 | 200 | } | |
| @@ -161,12 +161,14 @@ func validInterface(s string) bool { | |||||
| 161 | if len(s) > 255 { | 161 | if len(s) > 255 { | ||
| 162 | return false | 162 | return false | ||
| 163 | } | 163 | } | ||
| 164 | + | // strings.Cut, not SplitSeq: before Go 1.25 the iterator allocates. | |||
| 164 | n := 0 | 165 | n := 0 | ||
| 165 | - | for e := range strings.SplitSeq(s, ".") { | 166 | + | for more := true; more; n++ { |
| 167 | + | var e string | |||
| 168 | + | e, s, more = strings.Cut(s, ".") | |||
| 166 | if !validMember(e) { | 169 | if !validMember(e) { | ||
| 167 | return false | 170 | return false | ||
| 168 | } | 171 | } | ||
| 169 | - | n++ | |||
| 170 | } | 172 | } | ||
| 171 | return n >= 2 | 173 | return n >= 2 | ||
| 172 | } | 174 | } | ||
| @@ -182,7 +184,9 @@ func validBusName(s string) bool { | |||||
| 182 | s = s[1:] | 184 | s = s[1:] | ||
| 183 | } | 185 | } | ||
| 184 | n := 0 | 186 | n := 0 | ||
| 185 | - | for e := range strings.SplitSeq(s, ".") { | 187 | + | for more := true; more; n++ { |
| 188 | + | var e string | |||
| 189 | + | e, s, more = strings.Cut(s, ".") | |||
| 186 | if e == "" || !unique && e[0] >= '0' && e[0] <= '9' { | 190 | if e == "" || !unique && e[0] >= '0' && e[0] <= '9' { | ||
| 187 | return false | 191 | return false | ||
| 188 | } | 192 | } | ||
| @@ -191,7 +195,6 @@ func validBusName(s string) bool { | |||||
| 191 | return false | 195 | return false | ||
| 192 | } | 196 | } | ||
| 193 | } | 197 | } | ||
| 194 | - | n++ | |||
| 195 | } | 198 | } | ||
| 196 | return n >= 2 | 199 | return n >= 2 | ||
| 197 | } | 200 | } | ||