internal/pipewire: require appending marshaler
All checks were successful
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 2m24s
Test / Hakurei (push) Successful in 3m22s
Test / Hpkg (push) Successful in 4m9s
Test / Sandbox (race detector) (push) Successful in 4m17s
Test / Hakurei (race detector) (push) Successful in 5m8s
Test / Flake checks (push) Successful in 1m23s
All checks were successful
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 2m24s
Test / Hakurei (push) Successful in 3m22s
Test / Hpkg (push) Successful in 4m9s
Test / Sandbox (race detector) (push) Successful in 4m17s
Test / Hakurei (race detector) (push) Successful in 5m8s
Test / Flake checks (push) Successful in 1m23s
This eliminates all non-reflect allocations. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
e028a61fc1
commit
dcb22a61c0
@ -107,8 +107,9 @@ func SizeString[W Word | int](s string) W { return Size(W(len(s)) + 1) }
|
|||||||
// PODMarshaler is the interface implemented by an object that can
|
// PODMarshaler is the interface implemented by an object that can
|
||||||
// marshal itself into PipeWire POD encoding.
|
// marshal itself into PipeWire POD encoding.
|
||||||
type PODMarshaler interface {
|
type PODMarshaler interface {
|
||||||
// MarshalPOD encodes the receiver into PipeWire POD encoding and returns the result.
|
// MarshalPOD encodes the receiver into PipeWire POD encoding,
|
||||||
MarshalPOD() ([]byte, error)
|
// appends it to data, and returns the result.
|
||||||
|
MarshalPOD(data []byte) ([]byte, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// An UnsupportedTypeError is returned by [Marshal] when attempting
|
// An UnsupportedTypeError is returned by [Marshal] when attempting
|
||||||
@ -164,8 +165,9 @@ func appendInner(data []byte, f func(data []byte) ([]byte, error)) ([]byte, erro
|
|||||||
func marshalValueAppend(data []byte, v reflect.Value) ([]byte, error) {
|
func marshalValueAppend(data []byte, v reflect.Value) ([]byte, error) {
|
||||||
if v.CanInterface() && (v.Kind() != reflect.Pointer || !v.IsNil()) {
|
if v.CanInterface() && (v.Kind() != reflect.Pointer || !v.IsNil()) {
|
||||||
if m, ok := v.Interface().(PODMarshaler); ok {
|
if m, ok := v.Interface().(PODMarshaler); ok {
|
||||||
extraData, err := m.MarshalPOD()
|
var err error
|
||||||
return append(data, extraData...), err
|
data, err = m.MarshalPOD(data)
|
||||||
|
return data, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,8 +477,8 @@ func (d *SPADict) Size() Word {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MarshalPOD satisfies [PODMarshaler] as [SPADict] violates the POD type system.
|
// MarshalPOD satisfies [PODMarshaler] as [SPADict] violates the POD type system.
|
||||||
func (d *SPADict) MarshalPOD() ([]byte, error) {
|
func (d *SPADict) MarshalPOD(data []byte) ([]byte, error) {
|
||||||
return appendInner(nil, func(dataPrefix []byte) (data []byte, err error) {
|
return appendInner(data, func(dataPrefix []byte) (data []byte, err error) {
|
||||||
data = binary.NativeEndian.AppendUint32(dataPrefix, SPA_TYPE_Struct)
|
data = binary.NativeEndian.AppendUint32(dataPrefix, SPA_TYPE_Struct)
|
||||||
if data, err = MarshalAppend(data, d.NItems); err != nil {
|
if data, err = MarshalAppend(data, d.NItems); err != nil {
|
||||||
return
|
return
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user