Procházet zdrojové kódy

Merge pull request #615 from slingamn/sessions_optimization

optimize Sessions() at the expense of AddSession()
tags/v1.2.0-rc1
Daniel Oaks před 4 roky
rodič
revize
014a5fe63c
Žádný účet není propojen s e-mailovou adresou tvůrce revize
1 změnil soubory, kde provedl 5 přidání a 3 odebrání
  1. 5
    3
      irc/getters.go

+ 5
- 3
irc/getters.go Zobrazit soubor

43
 
43
 
44
 func (client *Client) Sessions() (sessions []*Session) {
44
 func (client *Client) Sessions() (sessions []*Session) {
45
 	client.stateMutex.RLock()
45
 	client.stateMutex.RLock()
46
-	sessions = make([]*Session, len(client.sessions))
47
-	copy(sessions, client.sessions)
46
+	sessions = client.sessions
48
 	client.stateMutex.RUnlock()
47
 	client.stateMutex.RUnlock()
49
 	return
48
 	return
50
 }
49
 }
102
 	}
101
 	}
103
 	// success, attach the new session to the client
102
 	// success, attach the new session to the client
104
 	session.client = client
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
 	return true
108
 	return true
107
 }
109
 }
108
 
110
 

Načítá se…
Zrušit
Uložit