util/slicesx: add FirstElementEqual and LastElementEqual

And update a few callers as examples of motivation. (there are a
couple others, but these are the ones where it's prettier)

Updates #cleanup

Change-Id: Ic8c5cb7af0a59c6e790a599136b591ebe16d38eb
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2024-09-11 16:32:05 -07:00
committed by Brad Fitzpatrick
parent 910462a8e0
commit cec779e771
5 changed files with 45 additions and 4 deletions

View File

@@ -47,6 +47,7 @@ import (
"tailscale.com/types/key"
"tailscale.com/types/logger"
"tailscale.com/util/set"
"tailscale.com/util/slicesx"
"tailscale.com/version"
)
@@ -1323,7 +1324,7 @@ func (s *Server) noteClientActivity(c *sclient) {
cs.activeClient.Store(c)
}
if sh := dup.sendHistory; len(sh) != 0 && sh[len(sh)-1] == c {
if slicesx.LastEqual(dup.sendHistory, c) {
// The client c was the last client to make activity
// in this set and it was already recorded. Nothing to
// do.