]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/cmd/compile/internal/escape/escape.go
cmd/compile: enable zero-copy string->[]byte conversions
[gostls13.git] / src / cmd / compile / internal / escape / escape.go
index 2882f9fda3e1e580ae91e878f0c26e568d187454..5f5dab31f7d95e53cf9ccbdd1d60c75361000c19 100644 (file)
@@ -345,16 +345,11 @@ func (b *batch) finish(fns []*ir.Func) {
 
                // If the result of a string->[]byte conversion is never mutated,
                // then it can simply reuse the string's memory directly.
-               //
-               // TODO(mdempsky): Enable in a subsequent CL. We need to ensure
-               // []byte("") evaluates to []byte{}, not []byte(nil).
-               if false {
-                       if n, ok := n.(*ir.ConvExpr); ok && n.Op() == ir.OSTR2BYTES && !loc.hasAttr(attrMutates) {
-                               if base.Flag.LowerM >= 1 {
-                                       base.WarnfAt(n.Pos(), "zero-copy string->[]byte conversion")
-                               }
-                               n.SetOp(ir.OSTR2BYTESTMP)
+               if n, ok := n.(*ir.ConvExpr); ok && n.Op() == ir.OSTR2BYTES && !loc.hasAttr(attrMutates) {
+                       if base.Flag.LowerM >= 1 {
+                               base.WarnfAt(n.Pos(), "zero-copy string->[]byte conversion")
                        }
+                       n.SetOp(ir.OSTR2BYTESTMP)
                }
        }
 }