mirror of
https://forge.sourceware.org/marek/gcc.git
synced 2026-02-22 03:47:02 -05:00
If a string([]byte) conversion is used immediately in a string
comparison, we don't need to copy the backing store of the byte
slice, as the string comparison doesn't hold any reference to
it. Instead, just create a string header from the byte slice and
pass it for comparison.
A new type of expression, String_value_expression, is introduced,
for constructing string headers.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/170894
* go.dg/cmpstring.go: New test.
From-SVN: r271021
14 lines
363 B
Go
14 lines
363 B
Go
// { dg-do compile }
|
|
// { dg-options "-fgo-debug-optimization" }
|
|
|
|
package p
|
|
|
|
func F(x []byte, y string) bool {
|
|
return string(x) == y // { dg-error "no copy string\\(\\\[\\\]byte\\)" }
|
|
}
|
|
|
|
func BytesEqual(x, y []byte) bool {
|
|
return string(x) == // { dg-error "no copy string\\(\\\[\\\]byte\\)" }
|
|
string(y) // { dg-error "no copy string\\(\\\[\\\]byte\\)" }
|
|
}
|