mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-23 00:51:35 +00:00
Ensure no memory allocations happen at hot path
This commit is contained in:
parent
c4e6894d6a
commit
67b8a7a53d
@ -72,7 +72,8 @@ func (s *sessionInfo) update(p *sessionPing) bool {
|
|||||||
if p.MTU >= 1280 || p.MTU == 0 {
|
if p.MTU >= 1280 || p.MTU == 0 {
|
||||||
s.theirMTU = p.MTU
|
s.theirMTU = p.MTU
|
||||||
}
|
}
|
||||||
s.coords = append([]byte{}, p.Coords...)
|
// allocate enough space for additional coords
|
||||||
|
s.coords = append(make([]byte, 0, len(p.Coords)+11), p.Coords...)
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
s.time = now
|
s.time = now
|
||||||
s.tstamp = p.Tstamp
|
s.tstamp = p.Tstamp
|
||||||
@ -426,8 +427,8 @@ func (sinfo *sessionInfo) doSend(bs []byte) {
|
|||||||
// To prevent using empty session keys
|
// To prevent using empty session keys
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var coords []byte
|
// code isn't multithreaded so appending to this is safe
|
||||||
coords = append(coords, sinfo.coords...)
|
coords := sinfo.coords
|
||||||
// Read IPv6 flowlabel field (20 bits).
|
// Read IPv6 flowlabel field (20 bits).
|
||||||
// Assumes packet at least contains IPv6 header.
|
// Assumes packet at least contains IPv6 header.
|
||||||
flowkey := uint64(bs[1]&0x0f)<<16 | uint64(bs[2])<<8 | uint64(bs[3])
|
flowkey := uint64(bs[1]&0x0f)<<16 | uint64(bs[2])<<8 | uint64(bs[3])
|
||||||
|
Loading…
Reference in New Issue
Block a user