diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-15 15:05:23 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-16 22:56:05 -0700 |
commit | a0e44530509d3b342b8011ac4467d957350f5ffa (patch) | |
tree | c36226f7d3c043b63a8f08f1d3b224ddf89f6844 /internal/fastio/noescape/noescape.go | |
parent | 921eeab75a87d07eaf9cec57dcdc8a3c276f291a (diff) |
Avoid io.Writer causing buffers to escape to the heap
Diffstat (limited to 'internal/fastio/noescape/noescape.go')
-rw-r--r-- | internal/fastio/noescape/noescape.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/internal/fastio/noescape/noescape.go b/internal/fastio/noescape/noescape.go new file mode 100644 index 0000000..02d25b5 --- /dev/null +++ b/internal/fastio/noescape/noescape.go @@ -0,0 +1,30 @@ +// Copyright (C) 2023 Luke Shumaker <lukeshu@lukeshu.com> +// +// SPDX-License-Identifier: GPL-2.0-or-later + +package noescape + +import ( + "io" + _ "unsafe" +) + +//go:noescape +//go:linkname Write io.Writer.Write +func Write(w io.Writer, dat []byte) (int, error) + +//go:noescape +//go:linkname WriteString io.StringWriter.WriteString +func WriteString(w io.Writer, dat string) (int, error) + +//go:noescape +//go:linkname WriteAt io.WriterAt.WriteAt +func WriteAt(w io.WriterAt, dat []byte, off int64) (int, error) + +//go:noescape +//go:linkname Read io.Reader.Read +func Read(w io.Reader, dat []byte) (int, error) + +//go:noescape +//go:linkname ReadAt io.ReaderAt.ReadAt +func ReadAt(w io.WriterAt, dat []byte, off int64) (int, error) |