aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--internal/pkg/pkg.go39
1 files changed, 26 insertions, 13 deletions
diff --git a/internal/pkg/pkg.go b/internal/pkg/pkg.go
index 154e20b0..1f765c1a 100644
--- a/internal/pkg/pkg.go
+++ b/internal/pkg/pkg.go
@@ -466,7 +466,7 @@ type Cache struct {
// Synchronises entry into exclusive artifacts for the cure method.
exclMu sync.Mutex
// Buffered I/O free list, must not be accessed directly.
- bufioPool sync.Pool
+ brPool, bwPool sync.Pool
// Unlocks the on-filesystem cache. Must only be called from Close.
unlock func()
@@ -548,6 +548,26 @@ func (c *Cache) unsafeIdent(a Artifact, encodeKind bool) (
return
}
+// getReader is like [bufio.NewReader] but for brPool.
+func (c *Cache) getReader(r io.Reader) *bufio.Reader {
+ br := c.brPool.Get().(*bufio.Reader)
+ br.Reset(r)
+ return br
+}
+
+// putReader adds br to brPool.
+func (c *Cache) putReader(br *bufio.Reader) { c.brPool.Put(br) }
+
+// getWriter is like [bufio.NewWriter] but for bwPool.
+func (c *Cache) getWriter(w io.Writer) *bufio.Writer {
+ bw := c.bwPool.Get().(*bufio.Writer)
+ bw.Reset(w)
+ return bw
+}
+
+// putWriter adds bw to bwPool.
+func (c *Cache) putWriter(bw *bufio.Writer) { c.bwPool.Put(bw) }
+
// A ChecksumMismatchError describes an [Artifact] with unexpected content.
type ChecksumMismatchError struct {
// Actual and expected checksums.
@@ -1214,13 +1234,6 @@ func (c *Cache) exitCure(a Artifact, curesExempt bool) {
<-c.cures
}
-// getWriter is like [bufio.NewWriter] but for bufioPool.
-func (c *Cache) getWriter(w io.Writer) *bufio.Writer {
- bw := c.bufioPool.Get().(*bufio.Writer)
- bw.Reset(w)
- return bw
-}
-
// measuredReader implements [io.ReadCloser] and measures the checksum during
// Close. If the underlying reader is not read to EOF, Close blocks until all
// remaining data is consumed and validated.
@@ -1303,9 +1316,6 @@ func (r *RContext) NewMeasuredReader(
return r.cache.newMeasuredReader(rc, checksum)
}
-// putWriter adds bw to bufioPool.
-func (c *Cache) putWriter(bw *bufio.Writer) { c.bufioPool.Put(bw) }
-
// cure implements Cure without checking the full dependency graph.
func (c *Cache) cure(a Artifact, curesExempt bool) (
pathname *check.Absolute,
@@ -1713,13 +1723,16 @@ func open(
msg: msg,
base: base,
+ identPool: sync.Pool{New: func() any { return new(extIdent) }},
+
ident: make(map[unique.Handle[ID]]unique.Handle[Checksum]),
identErr: make(map[unique.Handle[ID]]error),
identPending: make(map[unique.Handle[ID]]<-chan struct{}),
+
+ brPool: sync.Pool{New: func() any { return new(bufio.Reader) }},
+ bwPool: sync.Pool{New: func() any { return new(bufio.Writer) }},
}
c.ctx, c.cancel = context.WithCancel(ctx)
- c.identPool.New = func() any { return new(extIdent) }
- c.bufioPool.New = func() any { return new(bufio.Writer) }
if lock || !testing.Testing() {
if unlock, err := lockedfile.MutexAt(