summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-02-18 14:54:36 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-02-18 14:58:55 -0700
commitb2b51abfdc2eaefe6cf4aaf8645bbc7c52d89ff9 (patch)
tree59494397a1c7beb8d006863edc948b825aa1a533
parent1b773c966cdb6b38cc4bc73e218793db3a9442ba (diff)
fastio: NewAllWriter: Add a special case for io.Discard
-rw-r--r--compat/json/compat.go3
-rw-r--r--compat/json/testcompat_test.go4
-rw-r--r--internal/fastio/allwriter.go3
3 files changed, 6 insertions, 4 deletions
diff --git a/compat/json/compat.go b/compat/json/compat.go
index 0b86732..c96470d 100644
--- a/compat/json/compat.go
+++ b/compat/json/compat.go
@@ -15,7 +15,6 @@ import (
"strconv"
"git.lukeshu.com/go/lowmemjson"
- "git.lukeshu.com/go/lowmemjson/internal/fastio"
)
//nolint:stylecheck // ST1021 False positive; these aren't comments on individual types.
@@ -173,7 +172,7 @@ func Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error {
}
func Valid(data []byte) bool {
- formatter := lowmemjson.NewReEncoder(fastio.Discard, lowmemjson.ReEncoderConfig{
+ formatter := lowmemjson.NewReEncoder(io.Discard, lowmemjson.ReEncoderConfig{
Compact: true,
})
_, err := formatter.Write(data)
diff --git a/compat/json/testcompat_test.go b/compat/json/testcompat_test.go
index c186678..42cbf5c 100644
--- a/compat/json/testcompat_test.go
+++ b/compat/json/testcompat_test.go
@@ -7,10 +7,10 @@ package json
import (
"bytes"
"encoding/json"
+ "io"
_ "unsafe"
"git.lukeshu.com/go/lowmemjson"
- "git.lukeshu.com/go/lowmemjson/internal/fastio"
"git.lukeshu.com/go/lowmemjson/internal/jsonparse"
"git.lukeshu.com/go/lowmemjson/internal/jsonstring"
"git.lukeshu.com/go/lowmemjson/internal/jsonstruct"
@@ -25,7 +25,7 @@ var (
type scanner = lowmemjson.ReEncoderConfig
func checkValid(in []byte, scan *lowmemjson.ReEncoderConfig) error {
- return reencode(fastio.Discard, in, *scan)
+ return reencode(io.Discard, in, *scan)
}
func isValidNumber(s string) bool {
diff --git a/internal/fastio/allwriter.go b/internal/fastio/allwriter.go
index c587531..071d709 100644
--- a/internal/fastio/allwriter.go
+++ b/internal/fastio/allwriter.go
@@ -139,6 +139,9 @@ func (w writerYYNWrapper) WriteString(s string) (int, error) { return WriteStrin
// the io.Writer already has any of the other write methods, then its
// native version of those methods are used.
func NewAllWriter(inner io.Writer) AllWriter {
+ if inner == io.Discard {
+ return Discard
+ }
switch inner := inner.(type) {
// 3 Y bits
case AllWriter: // YYY: