mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	I'll try sorting, that's a good trick
This commit is contained in:
		
							parent
							
								
									cceecf4b1a
								
							
						
					
					
						commit
						2ae213c255
					
				
					 1 changed files with 5 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -19,6 +19,7 @@ import (
 | 
			
		|||
	"fmt"
 | 
			
		||||
	"math/rand"
 | 
			
		||||
	"net"
 | 
			
		||||
	"sort"
 | 
			
		||||
	"sync"
 | 
			
		||||
	"sync/atomic"
 | 
			
		||||
	"time"
 | 
			
		||||
| 
						 | 
				
			
			@ -249,6 +250,10 @@ func (iface *tcpInterface) handler(sock net.Conn, incoming bool) {
 | 
			
		|||
		var stack [][]byte
 | 
			
		||||
		put := func(msg []byte) {
 | 
			
		||||
			stack = append(stack, msg)
 | 
			
		||||
			sort.SliceStable(stack, func(i, j int) bool {
 | 
			
		||||
				// Sort in reverse order, with smallest messages at the end
 | 
			
		||||
				return len(stack[i]) >= len(stack[j])
 | 
			
		||||
			})
 | 
			
		||||
			for len(stack) > 32 {
 | 
			
		||||
				util_putBytes(stack[0])
 | 
			
		||||
				stack = stack[1:]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue