mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-11 06:29:29 +01:00
optimize Sessions() at the expense of AddSession()
This commit is contained in:
parent
8bca8a1752
commit
65834c0729
@ -43,8 +43,7 @@ func (server *Server) Languages() (lm *languages.Manager) {
|
|||||||
|
|
||||||
func (client *Client) Sessions() (sessions []*Session) {
|
func (client *Client) Sessions() (sessions []*Session) {
|
||||||
client.stateMutex.RLock()
|
client.stateMutex.RLock()
|
||||||
sessions = make([]*Session, len(client.sessions))
|
sessions = client.sessions
|
||||||
copy(sessions, client.sessions)
|
|
||||||
client.stateMutex.RUnlock()
|
client.stateMutex.RUnlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -102,7 +101,10 @@ func (client *Client) AddSession(session *Session) (success bool) {
|
|||||||
}
|
}
|
||||||
// success, attach the new session to the client
|
// success, attach the new session to the client
|
||||||
session.client = client
|
session.client = client
|
||||||
client.sessions = append(client.sessions, session)
|
newSessions := make([]*Session, len(client.sessions)+1)
|
||||||
|
copy(newSessions, client.sessions)
|
||||||
|
newSessions[len(newSessions)-1] = session
|
||||||
|
client.sessions = newSessions
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user