aboutsummaryrefslogtreecommitdiff
path: root/object/tree/parse.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-06-14 02:04:35 +0000
committerGravatar Runxi Yu2026-06-14 02:04:35 +0000
commit3ab488b38158eaa668473f0482a144fba8cf07b8 (patch)
treea0bbd36f4c1deecc37a036565620ba60da193573 /object/tree/parse.go
parentobject/store/packed: nosec is needed by taint analysis (diff)
object/tree: Pre-estimate entry count for single allocation
Diffstat (limited to 'object/tree/parse.go')
-rw-r--r--object/tree/parse.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/object/tree/parse.go b/object/tree/parse.go
index e89ce0fa..74f704f7 100644
--- a/object/tree/parse.go
+++ b/object/tree/parse.go
@@ -28,6 +28,11 @@ func Parse(body []byte, objectFormat id.ObjectFormat) (*Tree, error) {
idSize := objectFormat.Size()
seen := make(map[string]struct{})
+ const minEntryOverhead = 5 + 1 + 1 + 1 // mode, space, name, NUL
+ if estimate := len(body) / (minEntryOverhead + idSize); estimate > 0 {
+ tree.entries = make([]Entry, 0, estimate)
+ }
+
i := 0
for i < len(body) {
space := bytes.IndexByte(body[i:], ' ')