Commit 9de0a04a authored by Kamil Kisiel's avatar Kamil Kisiel

Reuse buffer in a few other places to save on allocations

parent 9627bcd9
...@@ -492,13 +492,12 @@ func (d *Decoder) loadBinString() error { ...@@ -492,13 +492,12 @@ func (d *Decoder) loadBinString() error {
} }
v := binary.LittleEndian.Uint32(b[:]) v := binary.LittleEndian.Uint32(b[:])
// TODO: use d.buf to reduce allocations? d.buf.Reset()
s := make([]byte, v) _, err = io.CopyN(&d.buf, d.r, int64(v))
_, err = io.ReadFull(d.r, s)
if err != nil { if err != nil {
return err return err
} }
d.push(string(s)) d.push(d.buf.String())
return nil return nil
} }
...@@ -508,13 +507,12 @@ func (d *Decoder) loadShortBinString() error { ...@@ -508,13 +507,12 @@ func (d *Decoder) loadShortBinString() error {
return err return err
} }
// TODO: use d.buf to reduce allocations? d.buf.Reset()
s := make([]byte, b) _, err = io.CopyN(&d.buf, d.r, int64(b))
_, err = io.ReadFull(d.r, s)
if err != nil { if err != nil {
return err return err
} }
d.push(string(s)) d.push(d.buf.String())
return nil return nil
} }
...@@ -825,13 +823,12 @@ func (d *Decoder) loadShortBinUnicode() error { ...@@ -825,13 +823,12 @@ func (d *Decoder) loadShortBinUnicode() error {
return err return err
} }
// TODO: use d.buf to save allocations? d.buf.Reset()
s := make([]byte, b) _, err = io.CopyN(&d.buf, d.r, int64(b))
_, err = io.ReadFull(d.r, s)
if err != nil { if err != nil {
return err return err
} }
d.push(string(s)) d.push(d.buf.String())
return nil return nil
} }
......
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