File tree 2 files changed +33
-1
lines changed
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -1553,7 +1553,7 @@ func mapclone2(t *maptype, src *hmap) *hmap {
1553
1553
}
1554
1554
1555
1555
if oldB >= dst .B { // main bucket bits in dst is less than oldB bits in src
1556
- dstBmap := (* bmap )(add (dst .buckets , uintptr (i )& bucketMask (dst .B )))
1556
+ dstBmap := (* bmap )(add (dst .buckets , ( uintptr (i )& bucketMask (dst .B )) * uintptr ( t . BucketSize )))
1557
1557
for dstBmap .overflow (t ) != nil {
1558
1558
dstBmap = dstBmap .overflow (t )
1559
1559
}
Original file line number Diff line number Diff line change
1
+ // run
2
+
3
+ // Copyright 2023 The Go Authors. All rights reserved.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file.
6
+
7
+ package main
8
+
9
+ import (
10
+ "fmt"
11
+ "maps"
12
+ )
13
+
14
+ func main () {
15
+ m := map [string ]struct {}{}
16
+
17
+ // Fill m up to the max for 4 buckets = 48 entries.
18
+ for i := 0 ; i < 48 ; i ++ {
19
+ m [fmt .Sprintf ("%d" , i )] = struct {}{}
20
+ }
21
+
22
+ // Add a 49th entry, to start a grow to 8 buckets.
23
+ m ["foo" ] = struct {}{}
24
+
25
+ // Remove that 49th entry. m is still growing to 8 buckets,
26
+ // but a clone of m will only have 4 buckets because it
27
+ // only needs to fit 48 entries.
28
+ delete (m , "foo" )
29
+
30
+ // Clone an 8-bucket map to a 4-bucket map.
31
+ _ = maps .Clone (m )
32
+ }
You can’t perform that action at this time.
0 commit comments