3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 10:42:52 +01:00

optimize Sessions() at the expense of AddSession()

This commit is contained in:
Shivaram Lingamneni 2019-08-02 00:20:31 -04:00
parent 8bca8a1752
commit 65834c0729

View File

@ -43,8 +43,7 @@ func (server *Server) Languages() (lm *languages.Manager) {
func (client *Client) Sessions() (sessions []*Session) {
client.stateMutex.RLock()
sessions = make([]*Session, len(client.sessions))
copy(sessions, client.sessions)
sessions = client.sessions
client.stateMutex.RUnlock()
return
}
@ -102,7 +101,10 @@ func (client *Client) AddSession(session *Session) (success bool) {
}
// success, attach the new session to the 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
}