mirror of
https://github.com/golang/go
synced 2024-11-11 21:50:21 -07:00
spec: clarify size hint for make of maps
For #19903. Change-Id: Ib28d08d45bfad653bcc1446f160b7b4a485529af Reviewed-on: https://go-review.googlesource.com/40393 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
55b56d2b2f
commit
b0e5a0c93c
@ -1,6 +1,6 @@
|
||||
<!--{
|
||||
"Title": "The Go Programming Language Specification",
|
||||
"Subtitle": "Version of March 24, 2017",
|
||||
"Subtitle": "Version of April 12, 2017",
|
||||
"Path": "/ref/spec"
|
||||
}-->
|
||||
|
||||
@ -5645,7 +5645,7 @@ make(T, n) slice slice of type T with length n and capacity n
|
||||
make(T, n, m) slice slice of type T with length n and capacity m
|
||||
|
||||
make(T) map map of type T
|
||||
make(T, n) map map of type T with initial space for n elements
|
||||
make(T, n) map map of type T with initial space for approximately n elements
|
||||
|
||||
make(T) channel unbuffered channel of type T
|
||||
make(T, n) channel buffered channel of type T, buffer size n
|
||||
@ -5668,9 +5668,15 @@ s := make([]int, 1e3) // slice with len(s) == cap(s) == 1000
|
||||
s := make([]int, 1<<63) // illegal: len(s) is not representable by a value of type int
|
||||
s := make([]int, 10, 0) // illegal: len(s) > cap(s)
|
||||
c := make(chan int, 10) // channel with a buffer size of 10
|
||||
m := make(map[string]int, 100) // map with initial space for 100 elements
|
||||
m := make(map[string]int, 100) // map with initial space for approximately 100 elements
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
Calling <code>make</code> with a map type and size hint <code>n</code> will
|
||||
create a map with initial space to hold <code>n</code> map elements.
|
||||
The precise behavior is implementation-dependent.
|
||||
</p>
|
||||
|
||||
|
||||
<h3 id="Appending_and_copying_slices">Appending to and copying slices</h3>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user