mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-25 10:14:36 +00:00
ipn/ipnlocal: remove another copy of slicesx.MapValues
We added this helper in 1e2e319e7d26. Remove this copy. Updates #cleanup Change-Id: I5b0681acc23692beed35951c9902ac9ceca0a8b9 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
92027d7ae0
commit
898cf06898
@ -25,6 +25,7 @@ import (
|
|||||||
"tailscale.com/types/logger"
|
"tailscale.com/types/logger"
|
||||||
"tailscale.com/util/execqueue"
|
"tailscale.com/util/execqueue"
|
||||||
"tailscale.com/util/set"
|
"tailscale.com/util/set"
|
||||||
|
"tailscale.com/util/slicesx"
|
||||||
"tailscale.com/util/testenv"
|
"tailscale.com/util/testenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -378,7 +379,7 @@ func (h *ExtensionHost) NotifyProfileChange(profile ipn.LoginProfileView, prefs
|
|||||||
h.currentPrefs = prefs
|
h.currentPrefs = prefs
|
||||||
h.currentProfile = profile
|
h.currentProfile = profile
|
||||||
// Get the callbacks to be invoked.
|
// Get the callbacks to be invoked.
|
||||||
cbs := collectValues(h.profileStateChangeCbs)
|
cbs := slicesx.MapValues(h.profileStateChangeCbs)
|
||||||
h.mu.Unlock()
|
h.mu.Unlock()
|
||||||
for _, cb := range cbs {
|
for _, cb := range cbs {
|
||||||
cb(profile, prefs, sameNode)
|
cb(profile, prefs, sameNode)
|
||||||
@ -402,7 +403,7 @@ func (h *ExtensionHost) NotifyProfilePrefsChanged(profile ipn.LoginProfileView,
|
|||||||
h.currentPrefs = newPrefs
|
h.currentPrefs = newPrefs
|
||||||
h.currentProfile = profile
|
h.currentProfile = profile
|
||||||
// Get the callbacks to be invoked.
|
// Get the callbacks to be invoked.
|
||||||
stateCbs := collectValues(h.profileStateChangeCbs)
|
stateCbs := slicesx.MapValues(h.profileStateChangeCbs)
|
||||||
h.mu.Unlock()
|
h.mu.Unlock()
|
||||||
for _, cb := range stateCbs {
|
for _, cb := range stateCbs {
|
||||||
cb(profile, newPrefs, true)
|
cb(profile, newPrefs, true)
|
||||||
@ -443,7 +444,7 @@ func (h *ExtensionHost) DetermineBackgroundProfile(profiles ipnext.ProfileStore)
|
|||||||
// Attempt to resolve the background profile using the registered
|
// Attempt to resolve the background profile using the registered
|
||||||
// background profile resolvers (e.g., [ipn/desktop.desktopSessionsExt] on Windows).
|
// background profile resolvers (e.g., [ipn/desktop.desktopSessionsExt] on Windows).
|
||||||
h.mu.Lock()
|
h.mu.Lock()
|
||||||
resolvers := collectValues(h.backgroundProfileResolvers)
|
resolvers := slicesx.MapValues(h.backgroundProfileResolvers)
|
||||||
h.mu.Unlock()
|
h.mu.Unlock()
|
||||||
for _, resolver := range resolvers {
|
for _, resolver := range resolvers {
|
||||||
if profile := resolver(profiles); profile.Valid() {
|
if profile := resolver(profiles); profile.Valid() {
|
||||||
@ -481,7 +482,7 @@ func (h *ExtensionHost) NotifyNewControlClient(cc controlclient.Client, profile
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
h.mu.Lock()
|
h.mu.Lock()
|
||||||
cbs := collectValues(h.newControlClientCbs)
|
cbs := slicesx.MapValues(h.newControlClientCbs)
|
||||||
h.mu.Unlock()
|
h.mu.Unlock()
|
||||||
if len(cbs) > 0 {
|
if len(cbs) > 0 {
|
||||||
ccShutdownCbs = make([]func(), 0, len(cbs))
|
ccShutdownCbs = make([]func(), 0, len(cbs))
|
||||||
@ -527,7 +528,7 @@ func (h *ExtensionHost) AuditLogger() ipnauth.AuditLogFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.mu.Lock()
|
h.mu.Lock()
|
||||||
providers := collectValues(h.auditLoggers)
|
providers := slicesx.MapValues(h.auditLoggers)
|
||||||
h.mu.Unlock()
|
h.mu.Unlock()
|
||||||
|
|
||||||
var loggers []ipnauth.AuditLogFunc
|
var loggers []ipnauth.AuditLogFunc
|
||||||
@ -642,17 +643,3 @@ type execQueue interface {
|
|||||||
Shutdown()
|
Shutdown()
|
||||||
Wait(context.Context) error
|
Wait(context.Context) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// collectValues is like [slices.Collect] of [maps.Values],
|
|
||||||
// but pre-allocates the slice to avoid reallocations.
|
|
||||||
// It returns nil if the map is empty.
|
|
||||||
func collectValues[K comparable, V any](m map[K]V) []V {
|
|
||||||
if len(m) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
s := make([]V, 0, len(m))
|
|
||||||
for _, v := range m {
|
|
||||||
s = append(s, v)
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user