使用gop缓存

This commit is contained in:
yangjiechina
2023-11-28 18:47:56 +08:00
parent 369f295452
commit 6fd7498ce0
4 changed files with 29 additions and 9 deletions

View File

@@ -1,6 +1,8 @@
package stream
import "github.com/yangjiechina/avformat/utils"
import (
"github.com/yangjiechina/avformat/utils"
)
type RingBuffer interface {
IsEmpty() bool
@@ -64,6 +66,7 @@ func (r *ringBuffer) Pop() interface{} {
}
element := r.data[r.head]
r.data[r.head] = nil
r.head = (r.head + 1) % cap(r.data)
r.size--
return element
@@ -86,7 +89,7 @@ func (r *ringBuffer) All() ([]interface{}, []interface{}) {
return nil, nil
}
if r.head < r.tail {
if r.head <= r.tail {
return r.data[r.head:], r.data[:r.tail]
} else {
return r.data[r.head:], nil