mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	get rid of an allocation in tunWriter's _write
This commit is contained in:
		
							parent
							
								
									71404f5270
								
							
						
					
					
						commit
						c2a8b4bb57
					
				
					 1 changed files with 4 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -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
 | 
			
		||||
// read w.tun.iface.IsTap() safely
 | 
			
		||||
func (w *tunWriter) _write(b []byte) {
 | 
			
		||||
	defer util.PutBytes(b)
 | 
			
		||||
	var written int
 | 
			
		||||
	var err error
 | 
			
		||||
	n := len(b)
 | 
			
		||||
	if n == 0 {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	written, err = w.tun.iface.Write(append(make([]byte, TUN_OFFSET_BYTES), b...), TUN_OFFSET_BYTES)
 | 
			
		||||
	util.PutBytes(b)
 | 
			
		||||
	temp := append(util.ResizeBytes(util.GetBytes(), TUN_OFFSET_BYTES), b...)
 | 
			
		||||
	defer util.PutBytes(temp)
 | 
			
		||||
	written, err = w.tun.iface.Write(temp, TUN_OFFSET_BYTES)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		w.tun.Act(w, func() {
 | 
			
		||||
			if !w.tun.isOpen {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue