summaryrefslogtreecommitdiff
path: root/internal/fastio
diff options
context:
space:
mode:
Diffstat (limited to 'internal/fastio')
-rw-r--r--internal/fastio/allwriter.go8
-rw-r--r--internal/fastio/noescape/noescape.go30
2 files changed, 35 insertions, 3 deletions
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 ///////////////////////////////////////////////////////////////////
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)