优化计数器性能

This commit is contained in:
GoEdgeLab
2023-12-25 16:41:07 +08:00
parent f10ce36feb
commit 5b6f572a47
3 changed files with 22 additions and 12 deletions

View File

@@ -16,7 +16,7 @@ type Item[T SupportedUIntType] struct {
spanSeconds int64
}
func NewItem[T SupportedUIntType](lifeSeconds int) *Item[T] {
func NewItem[T SupportedUIntType](lifeSeconds int) Item[T] {
if lifeSeconds <= 0 {
lifeSeconds = 60
}
@@ -27,7 +27,7 @@ func NewItem[T SupportedUIntType](lifeSeconds int) *Item[T] {
spanSeconds++
}
return &Item[T]{
return Item[T]{
lifeSeconds: int64(lifeSeconds),
spanSeconds: int64(spanSeconds),
lastUpdateTime: fasttime.Now().Unix(),
@@ -126,3 +126,7 @@ func (this *Item[T]) calculateSpanIndex(timestamp int64) int {
}
return index
}
func (this *Item[T]) IsOk() bool {
return this.lifeSeconds > 0
}