preallocate array

This commit is contained in:
Vladimir Stoilov 2022-09-20 16:55:01 +02:00 committed by Daniel
parent ab635bd0f0
commit 6f56e62be4

View file

@ -52,9 +52,11 @@ func (cs *connectionStore) list() []*Connection {
cs.rw.RLock() cs.rw.RLock()
defer cs.rw.RUnlock() defer cs.rw.RUnlock()
l := []*Connection{} l := make([]*Connection, len(cs.items))
index := 0
for _, conn := range cs.items { for _, conn := range cs.items {
l = append(l, conn) l[index] = conn
index++
} }
return l return l
} }