Przeglądaj źródła

optimize Sessions() at the expense of AddSession()

tags/v1.2.0-rc1
Shivaram Lingamneni 4 lat temu
rodzic
commit
65834c0729
1 zmienionych plików z 5 dodań i 3 usunięć
  1. 5
    3
      irc/getters.go

+ 5
- 3
irc/getters.go Wyświetl plik

@@ -43,8 +43,7 @@ func (server *Server) Languages() (lm *languages.Manager) {
43 43
 
44 44
 func (client *Client) Sessions() (sessions []*Session) {
45 45
 	client.stateMutex.RLock()
46
-	sessions = make([]*Session, len(client.sessions))
47
-	copy(sessions, client.sessions)
46
+	sessions = client.sessions
48 47
 	client.stateMutex.RUnlock()
49 48
 	return
50 49
 }
@@ -102,7 +101,10 @@ func (client *Client) AddSession(session *Session) (success bool) {
102 101
 	}
103 102
 	// success, attach the new session to the client
104 103
 	session.client = client
105
-	client.sessions = append(client.sessions, session)
104
+	newSessions := make([]*Session, len(client.sessions)+1)
105
+	copy(newSessions, client.sessions)
106
+	newSessions[len(newSessions)-1] = session
107
+	client.sessions = newSessions
106 108
 	return true
107 109
 }
108 110
 

Ładowanie…
Anuluj
Zapisz