Some changes for the benefit of performance for https://github.com/kataras/iris/pull/795

Former-commit-id: 4b2896381c78f35daaaf85d694c15e1cbdb78ac4
This commit is contained in:
Gerasimos (Makis) Maropoulos 2017-10-22 00:33:05 +03:00 committed by GitHub
parent 6f1d1d2fea
commit 9061d3d695

View File

@ -308,25 +308,22 @@ func (s *Server) leave(roomName string, connID string) (left bool) {
// GetTotalConnections returns the number of total connections // GetTotalConnections returns the number of total connections
func (s *Server) GetTotalConnections() int { func (s *Server) GetTotalConnections() int {
s.mu.RLock() s.mu.RLock()
defer s.mu.RUnlock() l:= len(s.connections)
return len(s.connections) s.mu.RUnlock()
return l
} }
// GetConnections returns all connections // GetConnections returns all connections
func (s *Server) GetConnections() []Connection { func (s *Server) GetConnections() []Connection {
s.mu.Lock() s.mu.RLock()
var conns []Connection conns:= make([]Connection, len(s.connections))
for _, conn := range s.connections { copy(conns, s.connections)
conns = append(conns, conn.value) s.mu.RUnlock()
}
s.mu.Unlock()
return conns return conns
} }
// GetConnection returns single connection // GetConnection returns single connection
func (s *Server) GetConnection(key string) Connection { func (s *Server) GetConnection(key string) Connection {
s.mu.Lock()
defer s.mu.Unlock()
return s.connections.get(key) return s.connections.get(key)
} }