forked from quic-go/quic-go
use the string optimization for map keys
This commit is contained in:
@@ -147,32 +147,29 @@ func (h *packetHandlerMap) logUsage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *packetHandlerMap) Add(id protocol.ConnectionID, handler packetHandler) bool /* was added */ {
|
func (h *packetHandlerMap) Add(id protocol.ConnectionID, handler packetHandler) bool /* was added */ {
|
||||||
sid := string(id)
|
|
||||||
|
|
||||||
h.mutex.Lock()
|
h.mutex.Lock()
|
||||||
defer h.mutex.Unlock()
|
defer h.mutex.Unlock()
|
||||||
|
|
||||||
if _, ok := h.handlers[sid]; ok {
|
if _, ok := h.handlers[string(id)]; ok {
|
||||||
h.logger.Debugf("Not adding connection ID %s, as it already exists.", id)
|
h.logger.Debugf("Not adding connection ID %s, as it already exists.", id)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
h.handlers[sid] = handler
|
h.handlers[string(id)] = handler
|
||||||
h.logger.Debugf("Adding connection ID %s.", id)
|
h.logger.Debugf("Adding connection ID %s.", id)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *packetHandlerMap) AddWithConnID(clientDestConnID, newConnID protocol.ConnectionID, fn func() packetHandler) bool {
|
func (h *packetHandlerMap) AddWithConnID(clientDestConnID, newConnID protocol.ConnectionID, fn func() packetHandler) bool {
|
||||||
sid := string(clientDestConnID)
|
|
||||||
h.mutex.Lock()
|
h.mutex.Lock()
|
||||||
defer h.mutex.Unlock()
|
defer h.mutex.Unlock()
|
||||||
|
|
||||||
if _, ok := h.handlers[sid]; ok {
|
if _, ok := h.handlers[string(clientDestConnID)]; ok {
|
||||||
h.logger.Debugf("Not adding connection ID %s for a new session, as it already exists.", clientDestConnID)
|
h.logger.Debugf("Not adding connection ID %s for a new session, as it already exists.", clientDestConnID)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
sess := fn()
|
sess := fn()
|
||||||
h.handlers[sid] = sess
|
h.handlers[string(clientDestConnID)] = sess
|
||||||
h.handlers[string(newConnID)] = sess
|
h.handlers[string(newConnID)] = sess
|
||||||
h.logger.Debugf("Adding connection IDs %s and %s for a new session.", clientDestConnID, newConnID)
|
h.logger.Debugf("Adding connection IDs %s and %s for a new session.", clientDestConnID, newConnID)
|
||||||
return true
|
return true
|
||||||
|
|||||||
Reference in New Issue
Block a user