Skip to content

Commit

Permalink
check Len before locking (#108)
Browse files Browse the repository at this point in the history
basically applying the same optimization that Pop has
  • Loading branch information
lrweck authored Dec 15, 2023
1 parent 17bcc37 commit 90f5a7a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ringbuffer/ringbuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func (rb *RingBuffer[T]) Pop() (T, bool) {
}

func (rb *RingBuffer[T]) PopN(n int64) ([]T, bool) {
if rb.Len() == 0 {
return nil, false
}
rb.mu.Lock()
content := rb.content

Expand Down

0 comments on commit 90f5a7a

Please sign in to comment.