Unverified Commit 211df3b9 authored by Whyrusleeping's avatar Whyrusleeping Committed by GitHub

Merge pull request #35 from Stebalien/feat/optimize

optimize byte reading
parents 63aa96ca 86493506
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment