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/jsonstring/encode_string.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'internal/jsonstring/encode_string.go') diff --git a/internal/jsonstring/encode_string.go b/internal/jsonstring/encode_string.go index 1b0c68a..fec2cc0 100644 --- a/internal/jsonstring/encode_string.go +++ b/internal/jsonstring/encode_string.go @@ -10,6 +10,7 @@ import ( "unicode/utf8" "git.lukeshu.com/go/lowmemjson/internal/fastio" + "git.lukeshu.com/go/lowmemjson/internal/fastio/noescape" ) // BackslashEscapeMode is describe in the main lowmemjson package @@ -35,7 +36,7 @@ func writeStringUnicodeEscape(w io.Writer, c rune) error { alphabet[(c>>4)&0xf], alphabet[(c>>0)&0xf], } - _, err := w.Write(buf[:]) + _, err := noescape.Write(w, buf[:]) return err } @@ -58,7 +59,7 @@ func writeStringShortEscape(w io.Writer, c rune) error { panic(fmt.Errorf("should not happen: writeStringShortEscape called with invalid rune: %q", c)) } buf := [2]byte{'\\', b} - _, err := w.Write(buf[:]) + _, err := noescape.Write(w, buf[:]) return err } -- cgit v1.2.3-2-g168b