From a0e44530509d3b342b8011ac4467d957350f5ffa Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2023 15:05:23 -0700 Subject: Avoid io.Writer causing buffers to escape to the heap --- internal/fastio/allwriter.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'internal/fastio/allwriter.go') diff --git a/internal/fastio/allwriter.go b/internal/fastio/allwriter.go index 9de8fdc..c587531 100644 --- a/internal/fastio/allwriter.go +++ b/internal/fastio/allwriter.go @@ -7,6 +7,8 @@ package fastio import ( "io" "unicode/utf8" + + "git.lukeshu.com/go/lowmemjson/internal/fastio/noescape" ) // interfaces ///////////////////////////////////////////////////////////////// @@ -28,18 +30,18 @@ type AllWriter interface { func WriteByte(w io.Writer, b byte) error { var buf [1]byte buf[0] = b - _, err := w.Write(buf[:]) + _, err := noescape.Write(w, buf[:]) return err } func WriteRune(w io.Writer, r rune) (int, error) { var buf [utf8.UTFMax]byte n := utf8.EncodeRune(buf[:], r) - return w.Write(buf[:n]) + return noescape.Write(w, buf[:n]) } func WriteString(w io.Writer, s string) (int, error) { - return w.Write([]byte(s)) + return noescape.Write(w, []byte(s)) } // wrappers /////////////////////////////////////////////////////////////////// -- cgit v1.2.3-2-g168b