mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Merge pull request #12659 from prymitive/memChunk
Short-cut common memChunk operations
This commit is contained in:
commit
42d55505f9
11
tsdb/head.go
11
tsdb/head.go
|
@ -2277,6 +2277,10 @@ type memChunk struct {
|
|||
|
||||
// len returns the length of memChunk list, including the element it was called on.
|
||||
func (mc *memChunk) len() (count int) {
|
||||
if mc.prev == nil {
|
||||
return 1
|
||||
}
|
||||
|
||||
elem := mc
|
||||
for elem != nil {
|
||||
count++
|
||||
|
@ -2288,6 +2292,9 @@ func (mc *memChunk) len() (count int) {
|
|||
// oldest returns the oldest element on the list.
|
||||
// For single element list this will be the same memChunk oldest() was called on.
|
||||
func (mc *memChunk) oldest() (elem *memChunk) {
|
||||
if mc.prev == nil {
|
||||
return mc
|
||||
}
|
||||
elem = mc
|
||||
for elem.prev != nil {
|
||||
elem = elem.prev
|
||||
|
@ -2300,6 +2307,9 @@ func (mc *memChunk) atOffset(offset int) (elem *memChunk) {
|
|||
if offset == 0 {
|
||||
return mc
|
||||
}
|
||||
if offset == 1 {
|
||||
return mc.prev
|
||||
}
|
||||
if offset < 0 {
|
||||
return nil
|
||||
}
|
||||
|
@ -2313,7 +2323,6 @@ func (mc *memChunk) atOffset(offset int) (elem *memChunk) {
|
|||
break
|
||||
}
|
||||
}
|
||||
|
||||
return elem
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue