(io.StringWriter).WriteString
for writing strings GO-P4008It is recommended to use (io.StringWriter).WriteString
instead of
(io.StringWriter).Write
or io.WriteString
for writing strings as it decreases
the number of allocations required, therefore improving performance.
package main
import (
"io"
)
func foo(w io.StringWriter) {
w.Write([]byte("foo"))
io.WriteString(w, "bar")
}
package main
import (
"io"
)
func foo(w io.StringWriter) {
w.WriteString("foo")
w.WriteString("bar")
}