3
0
mirror of https://github.com/ergochat/ergo.git synced 2026-04-26 18:48:22 +02:00

pointless optimization to (*caps.Set).Strings (#2386)

Doesn't change anything on arm64 (where atomic load is a plain MOV),
but reduces atomic instructions on arm64 and other platforms.
This commit is contained in:
Shivaram Lingamneni 2026-04-19 21:56:48 -07:00 committed by GitHub
parent de005ee69f
commit 7c8d81ac79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 3 deletions

View File

@ -5,6 +5,7 @@ package caps
import (
"fmt"
"github.com/ergochat/ergo/irc/utils"
)
@ -99,8 +100,10 @@ func (s *Set) Strings(version Version, values Values, maxLen int) (result []stri
var t utils.TokenLineBuilder
t.Initialize(maxLen, " ")
var local Set
asSlice := local[:]
utils.BitsetCopyLocal(asSlice, s[:])
var capab Capability
asSlice := s[:]
for capab = 0; capab < numCapabs; capab++ {
// XXX clients that only support CAP LS 301 cannot handle multiline
// responses. omit some CAPs in this case, forcing the response to fit on
@ -110,7 +113,7 @@ func (s *Set) Strings(version Version, values Values, maxLen int) (result []stri
continue
}
// skip any capabilities that are not enabled
if !utils.BitsetGet(asSlice, uint(capab)) {
if !utils.BitsetGetLocal(asSlice, uint(capab)) {
continue
}
capString := capab.Name()

View File

@ -107,3 +107,14 @@ func BenchmarkSetWrites(b *testing.B) {
set.Remove(LabeledResponse)
}
}
func BenchmarkSetStrings(b *testing.B) {
set := NewSet()
set.Add(AccountNotify)
set.Add(ZNCPlayback)
b.ResetTimer()
for i := 0; i < b.N; i++ {
set.Strings(Cap302, nil, 400)
}
}

View File

@ -346,9 +346,13 @@ func (set *ModeSet) AllModes() (result []Mode) {
return
}
var local ModeSet
asSlice := local[:]
utils.BitsetCopyLocal(asSlice, set[:])
var i Mode
for i = minMode; i <= maxMode; i++ {
if set.HasMode(i) {
if utils.BitsetGetLocal(asSlice, uint(i)-minMode) {
result = append(result, i)
}
}