From 3ab488b38158eaa668473f0482a144fba8cf07b8 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 14 Jun 2026 02:04:35 +0000 Subject: object/tree: Pre-estimate entry count for single allocation --- object/tree/parse.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'object/tree') 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:], ' ') -- cgit v1.3.1-10-gc9f91