Skip to content

Commit 3f4b9bf

Browse files
committed
Add comment about efficient map clear
1 parent fef0dc0 commit 3f4b9bf

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

internal/async/map_migratedfynedo.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ package async
44

55
// Map is a generic wrapper around [sync.Map].
66
type Map[K any, V any] struct {
7-
// once go1.20 is base, can use map[K]V
8-
// with K being Comparable instead of any
9-
// (CanvasObject, etc aren't Comparable for go1.19)
7+
// Use "comparable" as type constraint and map[K]V as the inner type
8+
// once Go 1.20 is our minimum version so interfaces can be used as keys.
109
m map[any]V
1110
}
1211

@@ -69,7 +68,5 @@ func (m *Map[K, V]) Store(key K, value V) {
6968

7069
// Clear removes all entries from the map.
7170
func (m *Map[K, V]) Clear() {
72-
for k := range m.m {
73-
delete(m.m, k)
74-
}
71+
m.m = make(map[any]V) // Use range-and-delete loop once Go 1.20 is the minimum version.
7572
}

0 commit comments

Comments
 (0)