aboutsummaryrefslogtreecommitdiff
path: root/object
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-06-13 15:53:02 +0000
committerGravatar Runxi Yu2026-06-13 15:53:02 +0000
commitec6448009b3f2e69ca9d20c9de3d0117675b7dd6 (patch)
tree55c3073d5ab6ceffecdec92a5d1a313182965ae6 /object
parentobject/store: Clarify ownership contract (diff)
object/store/packed: Don't copy on delta base cache hits.
Diffstat (limited to 'object')
-rw-r--r--object/store/packed/delta.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/object/store/packed/delta.go b/object/store/packed/delta.go
index 567fd679..e48e2c65 100644
--- a/object/store/packed/delta.go
+++ b/object/store/packed/delta.go
@@ -28,7 +28,11 @@ type deltaNode struct {
// unpackEntry reconstructs the object stored at offset in p,
// following ref- and ofs-delta chains within the pack.
//
-// Labels: Life-Independent.
+// A direct base-cache hit returns the shared cache buffer itself,
+// so the result may alias cache storage and must not be mutated;
+// delta-applied results are freshly allocated.
+//
+// Labels: Life-Parent, Mut-No.
func (packed *Packed) unpackEntry(p *pack, offset int) (packfile.EntryType, []byte, error) {
var zero packfile.EntryType
@@ -86,9 +90,11 @@ func (packed *Packed) unpackEntry(p *pack, offset int) (packfile.EntryType, []by
cur = baseOffset
}
- // A direct cache hit with no deltas to apply must be copied.
+ // A direct cache hit with no deltas to apply
+ // returns the shared cache buffer directly;
+ // callers are contractually Mut-No.
if len(chain) == 0 && fromCache {
- return baseType, bytes.Clone(base), nil
+ return baseType, base, nil
}
// Apply deltas back up the chain, caching each consumed base.