From ec17418c09fc23f90ef2ea5a9d5654adfa173c67 Mon Sep 17 00:00:00 2001 From: Alex Chan Date: Wed, 18 Nov 2026 09:49:24 +0000 Subject: [PATCH] ipn/prefs: reorder prefs.Equal() to put cheap comparisons first We were following this somewhat, but not consistently, and it wasn't obvious to new readers that it was the preferred pattern. Make it consistent and document the rule. Updates #cleanup Change-Id: Ib3f4d7eb3a64d9d6947a16b169cbfa5cfe8b8bc4 Signed-off-by: Alex Chan --- ipn/prefs.go | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/ipn/prefs.go b/ipn/prefs.go index ac9dd173c..655e689c7 100644 --- a/ipn/prefs.go +++ b/ipn/prefs.go @@ -693,12 +693,12 @@ func (p *Prefs) Equals(p2 *Prefs) bool { return false } - return p.ControlURL == p2.ControlURL && - p.RouteAll == p2.RouteAll && - p.ExitNodeID == p2.ExitNodeID && - p.ExitNodeIP == p2.ExitNodeIP && - p.AutoExitNode == p2.AutoExitNode && - p.InternalExitNodePrior == p2.InternalExitNodePrior && + // These comparisons are ordered to do cheap comparisons first + // in the short-circuits. + // + // TODO(alexc): We don't compare the value of Egg, a debugging flag + // that isn't used anywhere. Should we? + return p.RouteAll == p2.RouteAll && p.ExitNodeAllowLANAccess == p2.ExitNodeAllowLANAccess && p.CorpDNS == p2.CorpDNS && p.RunSSH == p2.RunSSH && @@ -708,25 +708,30 @@ func (p *Prefs) Equals(p2 *Prefs) bool { p.LoggedOut == p2.LoggedOut && p.NotepadURLs == p2.NotepadURLs && p.ShieldsUp == p2.ShieldsUp && + p.ForceDaemon == p2.ForceDaemon && p.NoSNAT == p2.NoSNAT && p.NoStatefulFiltering == p2.NoStatefulFiltering && p.NetfilterMode == p2.NetfilterMode && - p.OperatorUser == p2.OperatorUser && - p.Hostname == p2.Hostname && - p.ForceDaemon == p2.ForceDaemon && - slices.Equal(p.AdvertiseRoutes, p2.AdvertiseRoutes) && - slices.Equal(p.AdvertiseTags, p2.AdvertiseTags) && - slices.Equal(p.AdvertiseServices, p2.AdvertiseServices) && - p.Persist.Equals(p2.Persist) && - p.ProfileName == p2.ProfileName && - p.AutoUpdate.Equals(p2.AutoUpdate) && - p.AppConnector == p2.AppConnector && p.PostureChecking == p2.PostureChecking && - slices.EqualFunc(p.DriveShares, p2.DriveShares, drive.SharesEqual) && - p.NetfilterKind == p2.NetfilterKind && - p.Tailnet == p2.Tailnet && p.RemoteConfig == p2.RemoteConfig && compareUint16Ptrs(p.RelayServerPort, p2.RelayServerPort) && + p.ControlURL == p2.ControlURL && + p.ExitNodeID == p2.ExitNodeID && + p.ExitNodeIP == p2.ExitNodeIP && + p.AutoExitNode == p2.AutoExitNode && + p.InternalExitNodePrior == p2.InternalExitNodePrior && + p.Hostname == p2.Hostname && + p.OperatorUser == p2.OperatorUser && + p.ProfileName == p2.ProfileName && + p.NetfilterKind == p2.NetfilterKind && + p.Tailnet == p2.Tailnet && + slices.Equal(p.AdvertiseTags, p2.AdvertiseTags) && + slices.Equal(p.AdvertiseRoutes, p2.AdvertiseRoutes) && + slices.Equal(p.AdvertiseServices, p2.AdvertiseServices) && + p.Persist.Equals(p2.Persist) && + p.AutoUpdate.Equals(p2.AutoUpdate) && + p.AppConnector == p2.AppConnector && + slices.EqualFunc(p.DriveShares, p2.DriveShares, drive.SharesEqual) && slices.Equal(p.RelayServerStaticEndpoints, p2.RelayServerStaticEndpoints) }