From 3499a82785f8cb82bfe528875391d76d5e03c3de Mon Sep 17 00:00:00 2001 From: Ophestra Date: Thu, 15 Jan 2026 22:05:24 +0900 Subject: 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 --- internal/pkg/exec_test.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'internal/pkg/exec_test.go') diff --git a/internal/pkg/exec_test.go b/internal/pkg/exec_test.go index 97f72a38..558ab39b 100644 --- a/internal/pkg/exec_test.go +++ b/internal/pkg/exec_test.go @@ -50,7 +50,7 @@ func TestExec(t *testing.T) { nil, nil, nil, )), - pkg.MustPath("/.hakurei", false, stubArtifact{ + pkg.MustPath("/.hakurei", false, &stubArtifact{ kind: pkg.KindTar, params: []byte("empty directory"), cure: func(t *pkg.TContext) error { @@ -67,7 +67,7 @@ func TestExec(t *testing.T) { check.MustAbs("/opt/bin/testtool"), []string{"testtool"}, - pkg.MustPath("/proc/nonexistent", false, stubArtifact{ + pkg.MustPath("/proc/nonexistent", false, &stubArtifact{ kind: pkg.KindTar, params: []byte("doomed artifact"), cure: func(t *pkg.TContext) error { @@ -124,7 +124,7 @@ func TestExec(t *testing.T) { nil, nil, nil, )), - pkg.MustPath("/.hakurei", false, stubArtifact{ + pkg.MustPath("/.hakurei", false, &stubArtifact{ kind: pkg.KindTar, params: []byte("empty directory"), cure: func(t *pkg.TContext) error { @@ -150,7 +150,7 @@ func TestExec(t *testing.T) { check.MustAbs("/opt/bin/testtool"), []string{"testtool"}, - pkg.MustPath("/", true, stubArtifact{ + pkg.MustPath("/", true, &stubArtifact{ kind: pkg.KindTar, params: []byte("empty directory"), cure: func(t *pkg.TContext) error { @@ -176,13 +176,13 @@ func TestExec(t *testing.T) { check.MustAbs("/work/bin/testtool"), []string{"testtool"}, - pkg.MustPath("/", true, stubArtifact{ + pkg.MustPath("/", true, &stubArtifact{ kind: pkg.KindTar, params: []byte("empty directory"), cure: func(t *pkg.TContext) error { return os.MkdirAll(t.GetWorkDir().String(), 0700) }, - }), pkg.MustPath("/work/", false, stubArtifact{ + }), pkg.MustPath("/work/", false, &stubArtifact{ kind: pkg.KindTar, params: []byte("empty directory"), cure: func(t *pkg.TContext) error { @@ -207,13 +207,13 @@ func TestExec(t *testing.T) { check.MustAbs("/opt/bin/testtool"), []string{"testtool", "layers"}, - pkg.MustPath("/", true, stubArtifact{ + pkg.MustPath("/", true, &stubArtifact{ kind: pkg.KindTar, params: []byte("empty directory"), cure: func(t *pkg.TContext) error { return os.MkdirAll(t.GetWorkDir().String(), 0700) }, - }, stubArtifactF{ + }, &stubArtifactF{ kind: pkg.KindExec, params: []byte("test sample with dependencies"), @@ -222,7 +222,7 @@ func TestExec(t *testing.T) { pkg.ID{0xfe, 0}, nil, nil, nil, - ), stubArtifact{ + ), &stubArtifact{ kind: pkg.KindTar, params: []byte("empty directory"), @@ -255,7 +255,7 @@ func newTesttool() ( testtoolDestroy func(t *testing.T, base *check.Absolute, c *pkg.Cache), ) { // testtoolBin is built during go:generate and is not deterministic - testtool = overrideIdent{pkg.ID{0xfe, 0xff}, stubArtifact{ + testtool = overrideIdent{pkg.ID{0xfe, 0xff}, &stubArtifact{ kind: pkg.KindTar, cure: func(t *pkg.TContext) error { work := t.GetWorkDir() -- cgit v1.3.1