diff options
| author | 2026-06-14 02:04:35 +0000 | |
|---|---|---|
| committer | 2026-06-14 02:04:35 +0000 | |
| commit | 3ab488b38158eaa668473f0482a144fba8cf07b8 (patch) | |
| tree | a0bbd36f4c1deecc37a036565620ba60da193573 /object/tree | |
| parent | object/store/packed: nosec is needed by taint analysis (diff) | |
object/tree: Pre-estimate entry count for single allocation
Diffstat (limited to 'object/tree')
| -rw-r--r-- | object/tree/parse.go | 5 |
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:], ' ') |
