internal: don't double-wrap RawXMLValue

No need to go through another xml.Encoder.Encode roundtrip if the
value is already a RawXMLValue.
This commit is contained in:
Simon Ser 2022-05-03 18:20:55 +02:00
parent 8187cbf8c6
commit 6ae4814028

View File

@ -28,6 +28,9 @@ func NewRawXMLElement(name xml.Name, attr []xml.Attr, children []RawXMLValue) *R
// EncodeRawXMLElement encodes a value into a new RawXMLValue. The XML value // EncodeRawXMLElement encodes a value into a new RawXMLValue. The XML value
// can only be used for marshalling. // can only be used for marshalling.
func EncodeRawXMLElement(v interface{}) (*RawXMLValue, error) { func EncodeRawXMLElement(v interface{}) (*RawXMLValue, error) {
if raw, ok := v.(*RawXMLValue); ok {
return raw, nil
}
return &RawXMLValue{out: v}, nil return &RawXMLValue{out: v}, nil
} }