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:
parent
de005ee69f
commit
7c8d81ac79
@ -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()
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user