From fa0525301ed870d6a043fc0ae35c65f5ed080675 Mon Sep 17 00:00:00 2001 From: gernest Date: Thu, 13 Jul 2023 22:03:02 +0300 Subject: [PATCH] chore: correct use of sync.Pool --- file.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/file.go b/file.go index 38bc4c2..391dbe9 100644 --- a/file.go +++ b/file.go @@ -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) }