diff --git a/src/go/doc/reader.go b/src/go/doc/reader.go
index e84d6d9..2943c90 100644
--- a/src/go/doc/reader.go
+++ b/src/go/doc/reader.go
@@ -10,6 +10,7 @@
"go/ast"
"go/token"
"internal/lazyregexp"
+ "maps"
"path"
"slices"
"strconv"
@@ -792,11 +793,9 @@
// 1) move values
r.values = append(r.values, t.values...)
// 2) move factory functions
- for name, f := range t.funcs {
- // in a correct AST, package-level function names
- // are all different - no need to check for conflicts
- r.funcs[name] = f
- }
+ // in a correct AST, package-level function names
+ // are all different - no need to check for conflicts
+ maps.Copy(r.funcs, t.funcs)
// 3) move methods
if !predeclared {
for name, m := range t.methods {
diff --git a/src/internal/trace/summary.go b/src/internal/trace/summary.go
index 6609ed9..2baba52 100644
--- a/src/internal/trace/summary.go
+++ b/src/internal/trace/summary.go
@@ -6,6 +6,7 @@
import (
"cmp"
+ "maps"
"slices"
"strings"
"time"
@@ -170,13 +171,9 @@
func (s GoroutineExecStats) clone() (r GoroutineExecStats) {
r = s
r.BlockTimeByReason = make(map[string]time.Duration)
- for reason, dt := range s.BlockTimeByReason {
- r.BlockTimeByReason[reason] = dt
- }
+ maps.Copy(r.BlockTimeByReason, s.BlockTimeByReason)
r.RangeTime = make(map[string]time.Duration)
- for name, dt := range s.RangeTime {
- r.RangeTime[name] = dt
- }
+ maps.Copy(r.RangeTime, s.RangeTime)
return r
}
diff --git a/src/net/internal/socktest/switch.go b/src/net/internal/socktest/switch.go
index dea6d9288..a1c34eb 100644
--- a/src/net/internal/socktest/switch.go
+++ b/src/net/internal/socktest/switch.go
@@ -7,6 +7,7 @@
import (
"fmt"
+ "maps"
"sync"
)
@@ -45,9 +46,7 @@
func (sw *Switch) Sockets() Sockets {
sw.smu.RLock()
tab := make(Sockets, len(sw.sotab))
- for i, s := range sw.sotab {
- tab[i] = s
- }
+ maps.Copy(tab, sw.sotab)
sw.smu.RUnlock()
return tab
}
diff --git a/src/sync/atomic/example_test.go b/src/sync/atomic/example_test.go
index b378e30..9d21900 100644
--- a/src/sync/atomic/example_test.go
+++ b/src/sync/atomic/example_test.go
@@ -5,6 +5,7 @@
package atomic_test
import (
+ "maps"
"sync"
"sync/atomic"
"time"
@@ -63,9 +64,8 @@
defer mu.Unlock()
m1 := m.Load().(Map) // load current value of the data structure
m2 := make(Map) // create a new value
- for k, v := range m1 {
- m2[k] = v // copy all data from the current object to the new one
- }
+ // copy all data from the current object to the new one
+ maps.Copy(m2, m1)
m2[key] = val // do the update that we need
m.Store(m2) // atomically replace the current object with the new one
// At this point all new readers start working with the new version.
diff --git a/src/sync/map_reference_test.go b/src/sync/map_reference_test.go
index f98bb98..1909c7f 100644
--- a/src/sync/map_reference_test.go
+++ b/src/sync/map_reference_test.go
@@ -6,6 +6,7 @@
import (
isync "internal/sync"
+ "maps"
"sync"
"sync/atomic"
)
@@ -274,9 +275,7 @@
func (m *DeepCopyMap) dirty() map[any]any {
clean, _ := m.clean.Load().(map[any]any)
dirty := make(map[any]any, len(clean)+1)
- for k, v := range clean {
- dirty[k] = v
- }
+ maps.Copy(dirty, clean)
return dirty
}
diff --git a/src/text/template/funcs.go b/src/text/template/funcs.go
index ed9c7ea..33360ab 100644
--- a/src/text/template/funcs.go
+++ b/src/text/template/funcs.go
@@ -8,6 +8,7 @@
"errors"
"fmt"
"io"
+ "maps"
"net/url"
"reflect"
"strings"
@@ -90,9 +91,7 @@
// addFuncs adds to values the functions in funcs. It does no checking of the input -
// call addValueFuncs first.
func addFuncs(out, in FuncMap) {
- for name, fn := range in {
- out[name] = fn
- }
+ maps.Copy(out, in)
}
// goodFunc reports whether the function or method has the right result signature.