aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2025-03-21 16:07:20 -0700
committerGopher Robot <gobot@golang.org>2025-03-27 14:21:20 -0700
commita645bc5eb9b9fabc024c076140013a8ad87dded5 (patch)
tree70490f7e803e6a1926e264da0cc260b85bda4fb0 /src/runtime
parent6722c008c139a8abfe841275d12a601d7ea513a1 (diff)
downloadgo-a645bc5eb9b9fabc024c076140013a8ad87dded5.tar.xz
maps: implement faster clone
│ base │ experiment │ │ sec/op │ sec/op vs base │ MapClone-24 66.802m ± 7% 3.348m ± 2% -94.99% (p=0.000 n=10) Fixes #70836 Change-Id: I9e192b1ee82e18f5580ff18918307042a337fdcc Reviewed-on: https://go-review.googlesource.com/c/go/+/660175 Reviewed-by: Michael Pratt <mpratt@google.com> Auto-Submit: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/map_swiss.go17
1 files changed, 4 insertions, 13 deletions
diff --git a/src/runtime/map_swiss.go b/src/runtime/map_swiss.go
index a8fe87257a..a1e6ab6b9d 100644
--- a/src/runtime/map_swiss.go
+++ b/src/runtime/map_swiss.go
@@ -330,22 +330,13 @@ func mapinitnoop()
//go:linkname mapclone maps.clone
func mapclone(m any) any {
e := efaceOf(&m)
- e.data = unsafe.Pointer(mapclone2((*abi.SwissMapType)(unsafe.Pointer(e._type)), (*maps.Map)(e.data)))
+ typ := (*abi.SwissMapType)(unsafe.Pointer(e._type))
+ map_ := (*maps.Map)(e.data)
+ map_ = map_.Clone(typ)
+ e.data = (unsafe.Pointer)(map_)
return m
}
-func mapclone2(t *abi.SwissMapType, src *maps.Map) *maps.Map {
- dst := makemap(t, int(src.Used()), nil)
-
- var iter maps.Iter
- iter.Init(t, src)
- for iter.Next(); iter.Key() != nil; iter.Next() {
- dst.Put(t, iter.Key(), iter.Elem())
- }
-
- return dst
-}
-
// keys for implementing maps.keys
//
//go:linkname keys maps.keys