mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: initialize sparse slice literals dynamically
When a slice composite literal is sparse, initialize it dynamically
instead of statically.
s := []int{5:5, 20:20}
To initialize the backing store for s, use 2 constant writes instead
of copying from a static array with 21 entries.
This CL also fixes pathologies in the compiler when the slice is
*very* sparse.
Fixes #23780
Change-Id: Iae95c6e6f6a0e2994675cbc750d7a4dd6436b13b
Reviewed-on: https://go-review.googlesource.com/c/151319
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
1602e49701
commit
6fff980cf1
3 changed files with 28 additions and 2 deletions
|
|
@ -622,7 +622,7 @@ const (
|
|||
OMAPLIT // Type{List} (composite literal, Type is map)
|
||||
OSTRUCTLIT // Type{List} (composite literal, Type is struct)
|
||||
OARRAYLIT // Type{List} (composite literal, Type is array)
|
||||
OSLICELIT // Type{List} (composite literal, Type is slice)
|
||||
OSLICELIT // Type{List} (composite literal, Type is slice) Right.Int64() = slice length.
|
||||
OPTRLIT // &Left (left is composite literal)
|
||||
OCONV // Type(Left) (type conversion)
|
||||
OCONVIFACE // Type(Left) (type conversion, to interface)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue