Skip to content

Commit

Permalink
perf: optimize byte writing
Browse files Browse the repository at this point in the history
```
EncoderBigObject-32   4.541µ ± 2%   4.100µ ± 1%  -9.71% (p=0.000 n=15)

EncoderBigObject-32   1.045Gi ± 2%   1.157Gi ± 1%  +10.76% (p=0.000 n=15)
```
  • Loading branch information
tdakkota committed Apr 28, 2023
1 parent 3cdeec6 commit 1a6d8a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions w.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,18 @@ func (w *Writer) ResetWriter(out io.Writer) {

// byte writes a single byte.
func (w *Writer) byte(c byte) (fail bool) {
if w.stream == nil {
w.Buf = append(w.Buf, c)
return false
}
return writeStreamBytes(w, c)
}

func (w *Writer) twoBytes(c1, c2 byte) bool {
if w.stream == nil {
w.Buf = append(w.Buf, c1, c2)
return false
}
return writeStreamBytes(w, c1, c2)
}

Expand Down
3 changes: 3 additions & 0 deletions w_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ func writeStreamByteseq[S byteseq.Byteseq](w *Writer, s S) bool {
w.Buf = append(w.Buf, s...)
return false
}
return writeStreamByteseqSlow(w, s)
}

func writeStreamByteseqSlow[S byteseq.Byteseq](w *Writer, s S) bool {
if w.stream.fail() {
return true
}
Expand Down

0 comments on commit 1a6d8a5

Please sign in to comment.