compiler: avoid copy for string([]byte) conversion used in string comparison
authorCherry Zhang <cherryyz@google.com>
Wed, 8 May 2019 23:06:52 +0000 (23:06 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Wed, 8 May 2019 23:06:52 +0000 (23:06 +0000)
commit3407d1658f7d60cfb78293d61dfc21258efb0074
tree8aab6b19727ef793d37cb592a45bd808a3419700
parent8238b660fb6204b3e6968e9a6ed550b16c86b25e
compiler: avoid copy for string([]byte) conversion used in string comparison

    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
gcc/go/gofrontend/MERGE
gcc/go/gofrontend/expressions.cc
gcc/go/gofrontend/expressions.h
gcc/testsuite/ChangeLog
gcc/testsuite/go.dg/cmpstring.go [new file with mode: 0644]