1// run 2 3// Copyright 2024 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 7package main 8 9import ( 10 "maps" 11 _ "unsafe" 12) 13 14func main() { 15 for i := 0; i < 100; i++ { 16 f() 17 } 18} 19 20const NB = 4 21 22func f() { 23 // Make a map with NB buckets, at max capacity. 24 // 6.5 entries/bucket. 25 ne := NB * 13 / 2 26 m := map[int]int{} 27 for i := 0; i < ne; i++ { 28 m[i] = i 29 } 30 31 // delete/insert a lot, to hopefully get lots of overflow buckets 32 // and trigger a same-size grow. 33 ssg := false 34 for i := ne; i < ne+1000; i++ { 35 delete(m, i-ne) 36 m[i] = i 37 if sameSizeGrow(m) { 38 ssg = true 39 break 40 } 41 } 42 if !ssg { 43 return 44 } 45 46 // Insert 1 more entry, which would ordinarily trigger a growth. 47 // We can't grow while growing, so we instead go over our 48 // target capacity. 49 m[-1] = -1 50 51 // Cloning in this state will make a map with a destination bucket 52 // array twice the size of the source. 53 _ = maps.Clone(m) 54} 55 56//go:linkname sameSizeGrow runtime.sameSizeGrowForIssue69110Test 57func sameSizeGrow(m map[int]int) bool 58