5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-22 22:20:27 +00:00

get rid of an allocation in tunWriter's _write

This commit is contained in:
Arceliar 2019-11-28 12:00:00 -06:00
parent 71404f5270
commit c2a8b4bb57

View File

@ -25,14 +25,16 @@ func (w *tunWriter) writeFrom(from phony.Actor, b []byte) {
// write is pretty loose with the memory safety rules, e.g. it assumes it can // write is pretty loose with the memory safety rules, e.g. it assumes it can
// read w.tun.iface.IsTap() safely // read w.tun.iface.IsTap() safely
func (w *tunWriter) _write(b []byte) { func (w *tunWriter) _write(b []byte) {
defer util.PutBytes(b)
var written int var written int
var err error var err error
n := len(b) n := len(b)
if n == 0 { if n == 0 {
return return
} }
written, err = w.tun.iface.Write(append(make([]byte, TUN_OFFSET_BYTES), b...), TUN_OFFSET_BYTES) temp := append(util.ResizeBytes(util.GetBytes(), TUN_OFFSET_BYTES), b...)
util.PutBytes(b) defer util.PutBytes(temp)
written, err = w.tun.iface.Write(temp, TUN_OFFSET_BYTES)
if err != nil { if err != nil {
w.tun.Act(w, func() { w.tun.Act(w, func() {
if !w.tun.isOpen { if !w.tun.isOpen {