diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-01-15 22:05:24 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-01-15 23:30:43 +0900 |
| commit | 3499a82785f8cb82bfe528875391d76d5e03c3de (patch) | |
| tree | 66d82b1a95fc3137cfb7a2ffa82af0d84b613aa0 /internal/pkg/tar_test.go | |
| parent | 088d35e4e65f1a22d32ac66d223672ed923fa328 (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/tar_test.go')
| -rw-r--r-- | internal/pkg/tar_test.go | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/internal/pkg/tar_test.go b/internal/pkg/tar_test.go index f468b62a..d9635fb5 100644 --- a/internal/pkg/tar_test.go +++ b/internal/pkg/tar_test.go @@ -101,8 +101,11 @@ func checkTarHTTP( h.Write([]byte{byte(pkg.KindTar), 0, 0, 0, 0, 0, 0, 0}) h.Write([]byte{pkg.TarGzip, 0, 0, 0, 0, 0, 0, 0}) h.Write([]byte{byte(pkg.KindHTTPGet), 0, 0, 0, 0, 0, 0, 0}) - httpIdent := pkg.KindHTTPGet.Ident([]byte("file:///testdata")) - h.Write(httpIdent[:]) + + h0 := sha512.New384() + h0.Write([]byte{byte(pkg.KindHTTPGet), 0, 0, 0, 0, 0, 0, 0}) + h0.Write([]byte("file:///testdata")) + h.Write(h0.Sum(nil)) return pkg.ID(h.Sum(nil)) }() @@ -113,10 +116,6 @@ func checkTarHTTP( pkg.TarGzip, ) - if id := pkg.Ident(a); id != wantIdent { - t.Fatalf("Ident: %s, want %s", pkg.Encode(id), pkg.Encode(wantIdent)) - } - tarDir := stubArtifact{ kind: pkg.KindExec, params: []byte("directory containing a single regular file"), @@ -164,9 +163,9 @@ func checkTarHTTP( }, } // destroy these to avoid including it in flatten test case - defer newDestroyArtifactFunc(tarDir)(t, base, c) - defer newDestroyArtifactFunc(tarDirMulti)(t, base, c) - defer newDestroyArtifactFunc(tarDirType)(t, base, c) + defer newDestroyArtifactFunc(&tarDir)(t, base, c) + defer newDestroyArtifactFunc(&tarDirMulti)(t, base, c) + defer newDestroyArtifactFunc(&tarDirType)(t, base, c) cureMany(t, c, []cureStep{ {"file", a, base.Append( @@ -175,25 +174,25 @@ func checkTarHTTP( ), wantChecksum, nil}, {"directory", pkg.NewTar( - tarDir, + &tarDir, pkg.TarGzip, ), ignorePathname, wantChecksum, nil}, {"multiple entries", pkg.NewTar( - tarDirMulti, + &tarDirMulti, pkg.TarGzip, ), nil, pkg.Checksum{}, errors.New( "input directory does not contain a single regular file", )}, {"bad type", pkg.NewTar( - tarDirType, + &tarDirType, pkg.TarGzip, ), nil, pkg.Checksum{}, errors.New( "input directory does not contain a single regular file", )}, - {"error passthrough", pkg.NewTar(stubArtifact{ + {"error passthrough", pkg.NewTar(&stubArtifact{ kind: pkg.KindExec, params: []byte("doomed artifact"), cure: func(t *pkg.TContext) error { |
