mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 20:42:26 +00:00
encoding: avoid setting GVK unnecessarily
Setting the group/version/kind is not necessary when the object already has it. In that particular case some extra work and the data race when the same object is used multiple times in parallel can be avoided.
This commit is contained in:
parent
ad18954259
commit
f0aab8c984
@ -236,10 +236,14 @@ func (e WithVersionEncoder) Encode(obj Object, stream io.Writer) error {
|
||||
gvk = preferredGVK
|
||||
}
|
||||
}
|
||||
kind.SetGroupVersionKind(gvk)
|
||||
err = e.Encoder.Encode(obj, stream)
|
||||
kind.SetGroupVersionKind(oldGVK)
|
||||
return err
|
||||
|
||||
// The gvk only needs to be set if not already as desired.
|
||||
if gvk != oldGVK {
|
||||
kind.SetGroupVersionKind(gvk)
|
||||
defer kind.SetGroupVersionKind(oldGVK)
|
||||
}
|
||||
|
||||
return e.Encoder.Encode(obj, stream)
|
||||
}
|
||||
|
||||
// WithoutVersionDecoder clears the group version kind of a deserialized object.
|
||||
|
Loading…
Reference in New Issue
Block a user