aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/exec.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-01-15 22:05:24 +0900
committerOphestra <cat@gensokyo.uk>2026-01-15 23:30:43 +0900
commit3499a82785f8cb82bfe528875391d76d5e03c3de (patch)
tree66d82b1a95fc3137cfb7a2ffa82af0d84b613aa0 /internal/pkg/exec.go
parent088d35e4e65f1a22d32ac66d223672ed923fa328 (diff)
internal/pkg: cache computed identifiers
This eliminates duplicate identifier computations. The new implementation also significantly reduces allocations while computing identifier for a large dependency tree. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pkg/exec.go')
-rw-r--r--internal/pkg/exec.go46
1 files changed, 23 insertions, 23 deletions
diff --git a/internal/pkg/exec.go b/internal/pkg/exec.go
index 8d27d07d..f8131855 100644
--- a/internal/pkg/exec.go
+++ b/internal/pkg/exec.go
@@ -2,7 +2,6 @@ package pkg
import (
"bufio"
- "bytes"
"context"
"errors"
"fmt"
@@ -101,8 +100,9 @@ func (a *execNetArtifact) Checksum() Checksum { return a.checksum }
func (a *execNetArtifact) Kind() Kind { return KindExecNet }
// Params is [Checksum] concatenated with [KindExec] params.
-func (a *execNetArtifact) Params() []byte {
- return slices.Concat(a.checksum[:], a.execArtifact.Params())
+func (a *execNetArtifact) Params(ctx *IContext) {
+ ctx.GetHash().Write(a.checksum[:])
+ a.execArtifact.Params(ctx)
}
// Cure cures the [Artifact] in the container described by the caller. The
@@ -165,40 +165,40 @@ func NewExec(
// Kind returns the hardcoded [Kind] constant.
func (a *execArtifact) Kind() Kind { return KindExec }
-// Params returns paths, executable pathname and args concatenated together.
-func (a *execArtifact) Params() []byte {
- var buf bytes.Buffer
+// Params writes paths, executable pathname and args.
+func (a *execArtifact) Params(ctx *IContext) {
+ h := ctx.GetHash()
+
+ _0, _1 := []byte{0}, []byte{1}
for _, p := range a.paths {
if p.W {
- buf.WriteByte(1)
+ h.Write(_1)
} else {
- buf.WriteByte(0)
+ h.Write(_0)
}
if p.P != nil {
- buf.WriteString(p.P.String())
+ h.Write([]byte(p.P.String()))
} else {
- buf.WriteString("invalid P\x00")
+ h.Write([]byte("invalid P\x00"))
}
- buf.WriteByte(0)
+ h.Write(_0)
for _, d := range p.A {
- id := Ident(d)
- buf.Write(id[:])
+ ctx.WriteIdent(d)
}
- buf.WriteByte(0)
+ h.Write(_0)
}
- buf.WriteByte(0)
- buf.WriteString(a.dir.String())
- buf.WriteByte(0)
+ h.Write(_0)
+ h.Write([]byte(a.dir.String()))
+ h.Write(_0)
for _, e := range a.env {
- buf.WriteString(e)
+ h.Write([]byte(e))
}
- buf.WriteByte(0)
- buf.WriteString(a.path.String())
- buf.WriteByte(0)
+ h.Write(_0)
+ h.Write([]byte(a.path.String()))
+ h.Write(_0)
for _, arg := range a.args {
- buf.WriteString(arg)
+ h.Write([]byte(arg))
}
- return buf.Bytes()
}
// Dependencies returns a slice of all artifacts collected from caller-supplied