mirror of
https://github.com/golang/go
synced 2025-05-23 05:58:00 +00:00
cmd/compile: optimize unsafe.Slice generated code
We don't need a multiply when the element type is size 0 or 1. The panic functions don't return, so we don't need any post-call code (register restores, etc.). Change-Id: I0dcea5df56d29d7be26554ddca966b3903c672e5 Reviewed-on: https://go-review.googlesource.com/c/go/+/419754 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
@ -6,6 +6,8 @@
|
||||
|
||||
package codegen
|
||||
|
||||
import "unsafe"
|
||||
|
||||
// This file contains code generation tests related to the handling of
|
||||
// slice types.
|
||||
|
||||
@ -368,3 +370,16 @@ func SliceWithSubtractBound(a []int, b int) []int {
|
||||
// ppc64:"SUBC",-"NEG"
|
||||
return a[(3 - b):]
|
||||
}
|
||||
|
||||
// --------------------------------------- //
|
||||
// Code generation for unsafe.Slice //
|
||||
// --------------------------------------- //
|
||||
|
||||
func Slice1(p *byte, i int) []byte {
|
||||
// amd64:-"MULQ"
|
||||
return unsafe.Slice(p, i)
|
||||
}
|
||||
func Slice0(p *struct{}, i int) []struct{} {
|
||||
// amd64:-"MULQ"
|
||||
return unsafe.Slice(p, i)
|
||||
}
|
||||
|
Reference in New Issue
Block a user