Skip to content

Commit

Permalink
Merge pull request #35 from Stebalien/feat/optimize
Browse files Browse the repository at this point in the history
optimize byte reading
  • Loading branch information
whyrusleeping authored Aug 10, 2020
2 parents 63aa96c + 8649350 commit 211df3b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@ func CborReadHeader(br io.Reader) (byte, uint64, error) {
}

func readByteBuf(r io.Reader, scratch []byte) (byte, error) {
// Reading a single byte from these buffers is much faster than copying
// into a slice.
switch r := r.(type) {
case *bytes.Buffer:
return r.ReadByte()
case *bytes.Reader:
return r.ReadByte()
case *bufio.Reader:
return r.ReadByte()
}
n, err := r.Read(scratch[:1])
if err != nil {
return 0, err
Expand Down

0 comments on commit 211df3b

Please sign in to comment.