mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 10:08:15 -05:00
simplify buffer allocation
This commit is contained in:
parent
a6d81cc56d
commit
c49b93b39e
@ -29,17 +29,19 @@ func (w *BufferToBytesWriter) WriteMultiBuffer(mb MultiBuffer) error {
|
|||||||
return WriteAllBytes(w.Writer, mb[0].Bytes())
|
return WriteAllBytes(w.Writer, mb[0].Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cap(w.cache) < len(mb) {
|
||||||
|
w.cache = make([][]byte, 0, len(mb))
|
||||||
|
}
|
||||||
|
|
||||||
bs := w.cache
|
bs := w.cache
|
||||||
for _, b := range mb {
|
for _, b := range mb {
|
||||||
bs = append(bs, b.Bytes())
|
bs = append(bs, b.Bytes())
|
||||||
}
|
}
|
||||||
w.cache = bs
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
for idx := range w.cache {
|
for idx := range bs {
|
||||||
w.cache[idx] = nil
|
bs[idx] = nil
|
||||||
}
|
}
|
||||||
w.cache = w.cache[:0]
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
nb := net.Buffers(bs)
|
nb := net.Buffers(bs)
|
||||||
|
Loading…
Reference in New Issue
Block a user