mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15: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"
 | 
						"fmt"
 | 
				
			||||||
	"math/rand"
 | 
						"math/rand"
 | 
				
			||||||
	"net"
 | 
						"net"
 | 
				
			||||||
 | 
						"sort"
 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
	"sync/atomic"
 | 
						"sync/atomic"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
| 
						 | 
					@ -249,6 +250,10 @@ func (iface *tcpInterface) handler(sock net.Conn, incoming bool) {
 | 
				
			||||||
		var stack [][]byte
 | 
							var stack [][]byte
 | 
				
			||||||
		put := func(msg []byte) {
 | 
							put := func(msg []byte) {
 | 
				
			||||||
			stack = append(stack, msg)
 | 
								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 {
 | 
								for len(stack) > 32 {
 | 
				
			||||||
				util_putBytes(stack[0])
 | 
									util_putBytes(stack[0])
 | 
				
			||||||
				stack = stack[1:]
 | 
									stack = stack[1:]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue