diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-11-27 02:26:31 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-11-27 02:26:31 +0900 |
| commit | e028a61fc1567de71ba836a3a7caf64aef84b34c (patch) | |
| tree | 7a6a165e7f17f52ea43c05d283c2913e1cef3cde /internal/pipewire/pod.go | |
| parent | 73987be7d4c850f8b95babb8f68e6ccb6cafcee4 (diff) | |
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 <cat@gensokyo.uk>
Diffstat (limited to 'internal/pipewire/pod.go')
| -rw-r--r-- | internal/pipewire/pod.go | 8 |
1 files changed, 7 insertions, 1 deletions
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) { |
