forked from quic-go/quic-go
use a ring buffer for the datagram queue (#4223)
This commit is contained in:
@@ -8,7 +8,7 @@ type RingBuffer[T any] struct {
|
||||
full bool
|
||||
}
|
||||
|
||||
// Init preallocs a buffer with a certain size.
|
||||
// Init preallocates a buffer with a certain size.
|
||||
func (r *RingBuffer[T]) Init(size int) {
|
||||
r.ring = make([]T, size)
|
||||
}
|
||||
@@ -62,6 +62,16 @@ func (r *RingBuffer[T]) PopFront() T {
|
||||
return t
|
||||
}
|
||||
|
||||
// PeekFront returns the next element.
|
||||
// It must not be called when the buffer is empty, that means that
|
||||
// callers might need to check if there are elements in the buffer first.
|
||||
func (r *RingBuffer[T]) PeekFront() T {
|
||||
if r.Empty() {
|
||||
panic("github.com/quic-go/quic-go/internal/utils/ringbuffer: peek from an empty queue")
|
||||
}
|
||||
return r.ring[r.headPos]
|
||||
}
|
||||
|
||||
// Grow the maximum size of the queue.
|
||||
// This method assume the queue is full.
|
||||
func (r *RingBuffer[T]) grow() {
|
||||
|
||||
Reference in New Issue
Block a user