This avoids allocation when writing to bytes.Buffers and bufio.Writers, for
example.
R=golang-dev, rsc, r, consalus, r
CC=golang-dev
https://golang.org/cl/
4625068
UnreadRune() os.Error
}
+// stringWriter is the interface that wraps the WriteString method.
+type stringWriter interface {
+ WriteString(s string) (n int, err os.Error)
+}
+
// WriteString writes the contents of the string s to w, which accepts an array of bytes.
func WriteString(w Writer, s string) (n int, err os.Error) {
+ if sw, ok := w.(stringWriter); ok {
+ return sw.WriteString(s)
+ }
return w.Write([]byte(s))
}