mirror of
https://github.com/golang/go.git
synced 2024-09-21 10:28:27 +00:00
all: make use of sync.Map.Clear
Since CL 515015 added sync.Map.Clear method, we can use it to make the code simpler and clearer. Change-Id: I29edc969431b4fd95cd5fd864953a71ca1538dd3 Reviewed-on: https://go-review.googlesource.com/c/go/+/582015 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Joedian Reid <joedian@google.com> Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
parent
0e7f5cf30b
commit
b439f32859
@ -189,10 +189,7 @@ func (c *Cache[K, V]) Get(key K) (V, bool) {
|
||||
// TODO(jayconrod): Delete this after the package cache clearing functions
|
||||
// in internal/load have been removed.
|
||||
func (c *Cache[K, V]) Clear() {
|
||||
c.m.Range(func(key, value any) bool {
|
||||
c.m.Delete(key)
|
||||
return true
|
||||
})
|
||||
c.m.Clear()
|
||||
}
|
||||
|
||||
// Delete removes an entry from the map. It is safe to call Delete for an
|
||||
|
@ -169,10 +169,7 @@ func (v *Map) Init() *Map {
|
||||
v.keysMu.Lock()
|
||||
defer v.keysMu.Unlock()
|
||||
v.keys = v.keys[:0]
|
||||
v.m.Range(func(k, _ any) bool {
|
||||
v.m.Delete(k)
|
||||
return true
|
||||
})
|
||||
v.m.Clear()
|
||||
return v
|
||||
}
|
||||
|
||||
|
@ -22,18 +22,11 @@ var (
|
||||
extensions sync.Map // map[string][]string; slice values are append-only.
|
||||
)
|
||||
|
||||
func clearSyncMap(m *sync.Map) {
|
||||
m.Range(func(k, _ any) bool {
|
||||
m.Delete(k)
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
// setMimeTypes is used by initMime's non-test path, and by tests.
|
||||
func setMimeTypes(lowerExt, mixExt map[string]string) {
|
||||
clearSyncMap(&mimeTypes)
|
||||
clearSyncMap(&mimeTypesLower)
|
||||
clearSyncMap(&extensions)
|
||||
mimeTypes.Clear()
|
||||
mimeTypesLower.Clear()
|
||||
extensions.Clear()
|
||||
|
||||
for k, v := range lowerExt {
|
||||
mimeTypesLower.Store(k, v)
|
||||
|
Loading…
Reference in New Issue
Block a user