compiler: avoid copy for string([]byte) conversion used in string comparison

Programming / Compilers / GCC - ian [138bc75d-0d04-0410-961f-82ee72b054a4] - 8 May 2019 23:06 EDT

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.

ae77af58cfb compiler: avoid copy for string([]byte) conversion used in string comparison
gcc/go/gofrontend/MERGE | 2 +-
gcc/go/gofrontend/expressions.cc | 118 +++++++++++++++++++++++++++++++++++++--
gcc/go/gofrontend/expressions.h | 17 +++++-
gcc/testsuite/ChangeLog | 4 ++
gcc/testsuite/go.dg/cmpstring.go | 13 +++++
5 files changed, 148 insertions(+), 6 deletions(-)

Upstream: gcc.gnu.org


  • Share