}
break;
+ case OCMPSTR:
+ orderexpr(&n->left, order);
+ orderexpr(&n->right, order);
+ // Mark string(byteSlice) arguments to reuse byteSlice backing
+ // buffer during conversion. String comparison does not
+ // memorize the strings for later use, so it is safe.
+ if(n->left->op == OARRAYBYTESTR)
+ n->left->op = OARRAYBYTESTRTMP;
+ if(n->right->op == OARRAYBYTESTR)
+ n->right->op = OARRAYBYTESTRTMP;
+ break;
+
case OINDEXMAP:
// key must be addressable
orderexpr(&n->left, order);
// First such case is a m[string(k)] lookup where
// m is a string-keyed map and k is a []byte.
// Second such case is "<"+string(b)+">" concatenation where b is []byte.
+ // Third such case is string(b)=="foo" comparison where b is []byte.
if raceenabled && len(b) > 0 {
racereadrangepc(unsafe.Pointer(&b[0]),
t.Errorf("want %d, got %d", max+9, newmax)
}
}
+
+func TestCompareTempString(t *testing.T) {
+ s := "foo"
+ b := []byte(s)
+ n := testing.AllocsPerRun(1000, func() {
+ if string(b) != s {
+ t.Fatalf("strings are not equal: '%v' and '%v'", string(b), s)
+ }
+ if string(b) == s {
+ } else {
+ t.Fatalf("strings are not equal: '%v' and '%v'", string(b), s)
+ }
+ })
+ if n != 0 {
+ t.Fatalf("want 0 allocs, got %v", n)
+ }
+}