fix ring buffer (#1606)

This commit is contained in:
fztcjjl 2020-05-07 17:45:48 +08:00 committed by GitHub
parent 5387f73b5d
commit 30dc29e17f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -67,17 +67,12 @@ func (b *Buffer) Get(n int) []*Entry {
defer b.RUnlock()
// reset any invalid values
if n > b.size || n < 0 {
n = b.size
if n > len(b.vals) || n < 0 {
n = len(b.vals)
}
// create a delta
delta := b.size - n
// if all the values are less than delta
if len(b.vals) < delta {
return b.vals
}
delta := len(b.vals) - n
// return the delta set
return b.vals[delta:]