Skip to content

Commit

Permalink
chore: correct use of sync.Pool
Browse files Browse the repository at this point in the history
  • Loading branch information
gernest committed Jul 13, 2023
1 parent 873a7a7 commit fa05253
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,19 +765,17 @@ func getBufioReaderPool(size int) *sync.Pool {
return pool
}

var pageHeaderPool = &sync.Pool{}
var pageHeaderPool = &sync.Pool{
New: func() any {
return new(format.PageHeader)
},
}

func getPageHeader() *format.PageHeader {
h, _ := pageHeaderPool.Get().(*format.PageHeader)
if h != nil {
return h
}
return new(format.PageHeader)
return pageHeaderPool.Get().(*format.PageHeader)
}

func putPageHeader(h *format.PageHeader) {
if h != nil {
h.CRC = 0
pageHeaderPool.Put(h)
}
*h = format.PageHeader{}
pageHeaderPool.Put(h)
}

0 comments on commit fa05253

Please sign in to comment.