mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-02 23:34:48 +08:00
perf: use io.WriteString in writeString to avoid heap allocation (#2809)
writeString converted every string to []byte before calling io.Writer.Write, which Go escape analysis reports as escaping to the heap. io.WriteString uses the io.StringWriter fast path when available (the standard printer writer is a *bufio.Writer) and falls back to Write([]byte(txt)) otherwise. Fixes #2807 Co-authored-by: Pablo Garcia <pablito@MacBook-Neo-de-Pablo.local>
This commit is contained in:
+1
-1
@@ -50,7 +50,7 @@ func readStream(filename string) (io.Reader, error) {
|
||||
}
|
||||
|
||||
func writeString(writer io.Writer, txt string) error {
|
||||
_, errorWriting := writer.Write([]byte(txt))
|
||||
_, errorWriting := io.WriteString(writer, txt)
|
||||
return errorWriting
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user