From 23a2b71205894392d43ed10a8a7ce454d678c398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Tue, 13 May 2025 00:52:42 +0900 Subject: [PATCH] fix: count items --- item.go | 7 +------ pool.go | 16 +++++++++------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/item.go b/item.go index dcc3b4a..c31c221 100644 --- a/item.go +++ b/item.go @@ -138,12 +138,7 @@ func (b *Item[T]) destroybystat(stat status) { var v T b.val = v } - if stat.hasignored() { // ignore put - runtime.SetFinalizer(b, nil) - b.cfg = nil - return - } - b.pool.put(b) + b.pool.put(b, stat.hasignored()) } // ManualDestroy item and put it back to pool. diff --git a/pool.go b/pool.go index fe3603b..96ab30f 100644 --- a/pool.go +++ b/pool.go @@ -106,7 +106,7 @@ func (pool *Pool[T]) newempty() *Item[T] { return item.setautodestroy() } -func (pool *Pool[T]) put(item *Item[T]) { +func (pool *Pool[T]) put(item *Item[T], hasignore bool) { runtime.SetFinalizer(item, nil) item.cfg = nil @@ -118,15 +118,17 @@ func (pool *Pool[T]) put(item *Item[T]) { return } - _, exist := pool.dupmap.LoadOrStore(item, struct{}{}) - if exist { - panic("duplicated put") + if !hasignore { + _, exist := pool.dupmap.LoadOrStore(item, struct{}{}) + if exist { + panic("duplicated put") + } + + pool.pool.Put(item) + pool.incin() } - pool.pool.Put(item) - pool.decout() - pool.incin() } // New call this to generate an item.