mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-23 17:16:29 +00:00
util/checkchange: stop using deephash everywhere
Saves 45 KB from the min build, no longer pulling in deephash or util/hashx, both with unsafe code. It can actually be more efficient to not use deephash, as you don't have to walk all bytes of all fields recursively to answer that two things are not equal. Instead, you can just return false at the first difference you see. And then with views (as we use ~everywhere nowadays), the cloning the old value isn't expensive, as it's just a pointer under the hood. Updates #12614 Change-Id: I7b08616b8a09b3ade454bb5e0ac5672086fe8aec Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
28b1b4c3c1
commit
316afe7d02
@@ -651,9 +651,35 @@ var _VIPServiceCloneNeedsRegeneration = VIPService(struct {
|
||||
Active bool
|
||||
}{})
|
||||
|
||||
// Clone makes a deep copy of SSHPolicy.
|
||||
// The result aliases no memory with the original.
|
||||
func (src *SSHPolicy) Clone() *SSHPolicy {
|
||||
if src == nil {
|
||||
return nil
|
||||
}
|
||||
dst := new(SSHPolicy)
|
||||
*dst = *src
|
||||
if src.Rules != nil {
|
||||
dst.Rules = make([]*SSHRule, len(src.Rules))
|
||||
for i := range dst.Rules {
|
||||
if src.Rules[i] == nil {
|
||||
dst.Rules[i] = nil
|
||||
} else {
|
||||
dst.Rules[i] = src.Rules[i].Clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
return dst
|
||||
}
|
||||
|
||||
// A compilation failure here means this code must be regenerated, with the command at the top of this file.
|
||||
var _SSHPolicyCloneNeedsRegeneration = SSHPolicy(struct {
|
||||
Rules []*SSHRule
|
||||
}{})
|
||||
|
||||
// Clone duplicates src into dst and reports whether it succeeded.
|
||||
// To succeed, <src, dst> must be of types <*T, *T> or <*T, **T>,
|
||||
// where T is one of User,Node,Hostinfo,NetInfo,Login,DNSConfig,RegisterResponse,RegisterResponseAuth,RegisterRequest,DERPHomeParams,DERPRegion,DERPMap,DERPNode,SSHRule,SSHAction,SSHPrincipal,ControlDialPlan,Location,UserProfile,VIPService.
|
||||
// where T is one of User,Node,Hostinfo,NetInfo,Login,DNSConfig,RegisterResponse,RegisterResponseAuth,RegisterRequest,DERPHomeParams,DERPRegion,DERPMap,DERPNode,SSHRule,SSHAction,SSHPrincipal,ControlDialPlan,Location,UserProfile,VIPService,SSHPolicy.
|
||||
func Clone(dst, src any) bool {
|
||||
switch src := src.(type) {
|
||||
case *User:
|
||||
@@ -836,6 +862,15 @@ func Clone(dst, src any) bool {
|
||||
*dst = src.Clone()
|
||||
return true
|
||||
}
|
||||
case *SSHPolicy:
|
||||
switch dst := dst.(type) {
|
||||
case *SSHPolicy:
|
||||
*dst = *src.Clone()
|
||||
return true
|
||||
case **SSHPolicy:
|
||||
*dst = src.Clone()
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user