aboutsummaryrefslogtreecommitdiff
path: root/internal/compress/zlib/writer.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-06-08 05:39:15 +0000
committerGravatar Runxi Yu2026-06-08 05:39:15 +0000
commit2a82e5ab2a475484fb63da24ef8b96e1fc384f14 (patch)
tree29cbead07815da86276baf2a765354ceb16bbd94 /internal/compress/zlib/writer.go
parentinternal/compress/zlib: Fix imports and minor lint (diff)
signatureNo signature
internal/compress/zlib: Use lgo's safe sync.Pool
Diffstat (limited to 'internal/compress/zlib/writer.go')
-rw-r--r--internal/compress/zlib/writer.go17
1 files changed, 5 insertions, 12 deletions
diff --git a/internal/compress/zlib/writer.go b/internal/compress/zlib/writer.go
index ee3ce329..ae327e6d 100644
--- a/internal/compress/zlib/writer.go
+++ b/internal/compress/zlib/writer.go
@@ -9,9 +9,9 @@ import (
"fmt"
"hash"
"io"
- "sync"
"lindenii.org/go/furgit/internal/compress/flate"
+ "lindenii.org/go/lgo/sync"
)
// These constants are copied from the [flate] package, so that code that imports
@@ -38,11 +38,9 @@ type Writer struct {
}
//nolint:gochecknoglobals
-var writerPool = sync.Pool{
- New: func() any {
- return new(Writer)
- },
-}
+var writerPool = sync.NewPool(func() *Writer {
+ return new(Writer)
+})
// NewWriter creates a new [Writer].
// Writes to the returned Writer are compressed and written to w.
@@ -75,12 +73,7 @@ func NewWriterLevelDict(w io.Writer, level int, dict []byte) (*Writer, error) {
return nil, fmt.Errorf("zlib: invalid compression level: %d", level)
}
- v := writerPool.Get()
-
- z, ok := v.(*Writer)
- if !ok {
- panic("zlib: pool returned unexpected type")
- }
+ z := writerPool.Get()
// flate.Writer can only be Reset with the same level/dictionary mode.
// Reuse it only when the configuration is unchanged and dictionary-free.