Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
fix: 更新性能, 修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkgos committed Apr 18, 2024
1 parent 764c89a commit e8b880e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ type fieldContainer struct {
Fields []Field
}

func (c *fieldContainer) reset() *fieldContainer {
c.Fields = c.Fields[:0]
return c
}

type fieldPool struct {
pool sync.Pool
}
Expand All @@ -27,10 +32,10 @@ func newFieldPool() *fieldPool {
}

func (p *fieldPool) Get() *fieldContainer {
return p.pool.Get().(*fieldContainer)
c := p.pool.Get().(*fieldContainer)
return c.reset()
}

func (p *fieldPool) Put(c *fieldContainer) {
c.Fields = c.Fields[:0]
p.pool.Put(c)
p.pool.Put(c.reset())
}

0 comments on commit e8b880e

Please sign in to comment.