cmd/cloner,*: revert: optimize nillable slice cloner

This reverts commit ee90cd02fd.

The outcome is not identical for empty slices. Cloner really needs
tests!

Updates #9601

Signed-off-by: James Tucker <james@tailscale.com>
This commit is contained in:
James Tucker
2023-09-29 18:15:53 -07:00
committed by James Tucker
parent ee90cd02fd
commit 324f0d5f80
5 changed files with 58 additions and 34 deletions

View File

@@ -23,9 +23,11 @@ func (src *Match) Clone() *Match {
dst.IPProto = append(src.IPProto[:0:0], src.IPProto...)
dst.Srcs = append(src.Srcs[:0:0], src.Srcs...)
dst.Dsts = append(src.Dsts[:0:0], src.Dsts...)
dst.Caps = append([]CapMatch(nil), make([]CapMatch, len(src.Caps))...)
for i := range dst.Caps {
dst.Caps[i] = *src.Caps[i].Clone()
if src.Caps != nil {
dst.Caps = make([]CapMatch, len(src.Caps))
for i := range dst.Caps {
dst.Caps[i] = *src.Caps[i].Clone()
}
}
return dst
}