mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-05-19 18:59:08 -04:00
reduce memory allocation in mux
This commit is contained in:
@@ -19,7 +19,7 @@ type SessionManager struct {
|
||||
func NewSessionManager() *SessionManager {
|
||||
return &SessionManager{
|
||||
count: 0,
|
||||
sessions: make(map[uint16]*Session, 32),
|
||||
sessions: make(map[uint16]*Session, 16),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,10 @@ func (m *SessionManager) Add(s *Session) {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
if m.closed {
|
||||
return
|
||||
}
|
||||
|
||||
m.sessions[s.ID] = s
|
||||
}
|
||||
|
||||
@@ -65,6 +69,10 @@ func (m *SessionManager) Remove(id uint16) {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
if m.closed {
|
||||
return
|
||||
}
|
||||
|
||||
delete(m.sessions, id)
|
||||
}
|
||||
|
||||
@@ -111,7 +119,7 @@ func (m *SessionManager) Close() {
|
||||
s.output.Close()
|
||||
}
|
||||
|
||||
m.sessions = make(map[uint16]*Session)
|
||||
m.sessions = nil
|
||||
}
|
||||
|
||||
type Session struct {
|
||||
|
||||
Reference in New Issue
Block a user