From e028a61fc1567de71ba836a3a7caf64aef84b34c Mon Sep 17 00:00:00 2001 From: Ophestra Date: Thu, 27 Nov 2025 02:26:31 +0900 Subject: internal/pipewire: preallocate for known size This is still not efficient by any means, but it should eliminate most non-reflect allocation (all allocation if PODMarshaler is not used). Signed-off-by: Ophestra --- internal/pipewire/pod.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'internal/pipewire/pod.go') diff --git a/internal/pipewire/pod.go b/internal/pipewire/pod.go index 80c798e8..3a94db5d 100644 --- a/internal/pipewire/pod.go +++ b/internal/pipewire/pod.go @@ -125,7 +125,13 @@ type UnsupportedSizeError int func (e UnsupportedSizeError) Error() string { return "size out of range: " + strconv.Itoa(int(e)) } // Marshal returns the PipeWire POD encoding of v. -func Marshal(v any) ([]byte, error) { return MarshalAppend(make([]byte, 0), v) } +func Marshal(v any) ([]byte, error) { + var data []byte + if s, ok := v.(KnownSize); ok { + data = make([]byte, 0, s.Size()) + } + return MarshalAppend(data, v) +} // MarshalAppend appends the PipeWire POD encoding of v to data. func MarshalAppend(data []byte, v any) ([]byte, error) { -- cgit v1.3.1