use struct{} instead of bool in map just as a set

This commit is contained in:
mawei 2020-05-21 17:51:12 +08:00
parent 798051a0e4
commit 4a5adad35b

View file

@ -11,8 +11,8 @@ import (
type windowUpdateQueue struct { type windowUpdateQueue struct {
mutex sync.Mutex mutex sync.Mutex
queue map[protocol.StreamID]bool // used as a set queue map[protocol.StreamID]struct{} // used as a set
queuedConn bool // connection-level window update queuedConn bool // connection-level window update
streamGetter streamGetter streamGetter streamGetter
connFlowController flowcontrol.ConnectionFlowController connFlowController flowcontrol.ConnectionFlowController
@ -25,7 +25,7 @@ func newWindowUpdateQueue(
cb func(wire.Frame), cb func(wire.Frame),
) *windowUpdateQueue { ) *windowUpdateQueue {
return &windowUpdateQueue{ return &windowUpdateQueue{
queue: make(map[protocol.StreamID]bool), queue: make(map[protocol.StreamID]struct{}),
streamGetter: streamGetter, streamGetter: streamGetter,
connFlowController: connFC, connFlowController: connFC,
callback: cb, callback: cb,
@ -34,7 +34,7 @@ func newWindowUpdateQueue(
func (q *windowUpdateQueue) AddStream(id protocol.StreamID) { func (q *windowUpdateQueue) AddStream(id protocol.StreamID) {
q.mutex.Lock() q.mutex.Lock()
q.queue[id] = true q.queue[id] = struct{}{}
q.mutex.Unlock() q.mutex.Unlock()
} }