cache length of StreamFrameQueue

This commit is contained in:
Marten Seemann
2016-05-26 16:16:57 +07:00
parent c66fd78eaf
commit a5e03bef8a
2 changed files with 12 additions and 1 deletions

View File

@@ -13,6 +13,7 @@ type streamFrameQueue struct {
frames []*frames.StreamFrame
mutex sync.RWMutex
len int
byteLen protocol.ByteCount
}
@@ -30,6 +31,7 @@ func (q *streamFrameQueue) Push(frame *frames.StreamFrame, prio bool) {
}
q.byteLen += protocol.ByteCount(len(frame.Data))
q.len++
}
// Len returns the total number of queued StreamFrames
@@ -37,7 +39,7 @@ func (q *streamFrameQueue) Len() int {
q.mutex.RLock()
defer q.mutex.RUnlock()
return len(q.prioFrames) + len(q.frames)
return q.len
}
// ByteLen returns the total number of bytes queued
@@ -79,6 +81,7 @@ func (q *streamFrameQueue) Pop(maxLength protocol.ByteCount) *frames.StreamFrame
}
q.byteLen -= protocol.ByteCount(len(frame.Data))
q.len--
return frame
}