cmd/cloner,*: optimize nillable slice cloner

A wild @josharian appears with a good suggestion for a refactor, thanks
Josh!

Updates #9410
Signed-off-by: James Tucker <james@tailscale.com>
This commit is contained in:
James Tucker
2023-09-29 17:29:17 -07:00
committed by James Tucker
parent e91e96dfa5
commit ee90cd02fd
5 changed files with 34 additions and 58 deletions

View File

@@ -23,11 +23,9 @@ 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...)
if src.Caps != nil {
dst.Caps = make([]CapMatch, len(src.Caps))
for i := range dst.Caps {
dst.Caps[i] = *src.Caps[i].Clone()
}
dst.Caps = append([]CapMatch(nil), make([]CapMatch, len(src.Caps))...)
for i := range dst.Caps {
dst.Caps[i] = *src.Caps[i].Clone()
}
return dst
}