Shuffle in place

Don't create a copy and save the copy, not necessary any more.
This commit is contained in:
Sean Chittenden 2016-03-28 14:02:27 -07:00
parent e230b3a3b7
commit 0b0a07a280
1 changed files with 1 additions and 5 deletions

View File

@ -173,15 +173,11 @@ func (sc *serverConfig) removeServerByKey(targetKey *server_details.Key) {
// shuffleServers shuffles the server list in place // shuffleServers shuffles the server list in place
func (sc *serverConfig) shuffleServers() { func (sc *serverConfig) shuffleServers() {
newServers := make([]*server_details.ServerDetails, len(sc.servers))
copy(newServers, sc.servers)
// Shuffle server list // Shuffle server list
for i := len(sc.servers) - 1; i > 0; i-- { for i := len(sc.servers) - 1; i > 0; i-- {
j := rand.Int31n(int32(i + 1)) j := rand.Int31n(int32(i + 1))
newServers[i], newServers[j] = newServers[j], newServers[i] sc.servers[i], sc.servers[j] = sc.servers[j], sc.servers[i]
} }
sc.servers = newServers
} }
// FindServer takes out an internal "read lock" and searches through the list // FindServer takes out an internal "read lock" and searches through the list