mirror of
https://github.com/golang/go
synced 2024-11-15 03:40:29 -07:00
566e3e074c
This triggers three times while building std, once in image/png and twice in go/internal/gccgoimporter. There are no instances in std in which a more aggressive optimization would have triggered. This doesn't necessarily avoid an allocation, because escape analysis is already able in many cases to use a temporary backing for the string, but it does at a minimum avoid the runtime call and copy. Fixes #24937 Change-Id: I7019e85638ba8cd7e2f03890e672558b858579bc Reviewed-on: https://go-review.googlesource.com/108035 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
16 lines
305 B
Go
16 lines
305 B
Go
// run
|
|
|
|
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
func main() {
|
|
x := []byte{'a'}
|
|
switch string(x) {
|
|
case func() string { x[0] = 'b'; return "b" }():
|
|
panic("FAIL")
|
|
}
|
|
}
|