mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	update phony, add mobile versions of util bytes functions that don't try to store anything
This commit is contained in:
		
							parent
							
								
									5c0f79c4ed
								
							
						
					
					
						commit
						a64f7320d8
					
				
					 5 changed files with 34 additions and 17 deletions
				
			
		
							
								
								
									
										13
									
								
								src/util/bytes_mobile.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								src/util/bytes_mobile.go
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,13 @@
 | 
			
		|||
//+build mobile
 | 
			
		||||
 | 
			
		||||
package util
 | 
			
		||||
 | 
			
		||||
// On mobile, just return a nil slice.
 | 
			
		||||
func GetBytes() []byte {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// On mobile, don't do anything.
 | 
			
		||||
func PutBytes(bs []byte) {
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										18
									
								
								src/util/bytes_other.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								src/util/bytes_other.go
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,18 @@
 | 
			
		|||
//+build !mobile
 | 
			
		||||
 | 
			
		||||
package util
 | 
			
		||||
 | 
			
		||||
import "sync"
 | 
			
		||||
 | 
			
		||||
// This is used to buffer recently used slices of bytes, to prevent allocations in the hot loops.
 | 
			
		||||
var byteStore = sync.Pool{New: func() interface{} { return []byte(nil) }}
 | 
			
		||||
 | 
			
		||||
// Gets an empty slice from the byte store.
 | 
			
		||||
func GetBytes() []byte {
 | 
			
		||||
	return byteStore.Get().([]byte)[:0]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Puts a slice in the store.
 | 
			
		||||
func PutBytes(bs []byte) {
 | 
			
		||||
	byteStore.Put(bs)
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -6,7 +6,6 @@ import (
 | 
			
		|||
	"runtime"
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"sync"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -25,19 +24,6 @@ func UnlockThread() {
 | 
			
		|||
	runtime.UnlockOSThread()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// This is used to buffer recently used slices of bytes, to prevent allocations in the hot loops.
 | 
			
		||||
var byteStore = sync.Pool{New: func() interface{} { return []byte(nil) }}
 | 
			
		||||
 | 
			
		||||
// Gets an empty slice from the byte store.
 | 
			
		||||
func GetBytes() []byte {
 | 
			
		||||
	return byteStore.Get().([]byte)[:0]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Puts a slice in the store.
 | 
			
		||||
func PutBytes(bs []byte) {
 | 
			
		||||
	byteStore.Put(bs)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Gets a slice of the appropriate length, reusing existing slice capacity when possible
 | 
			
		||||
func ResizeBytes(bs []byte, length int) []byte {
 | 
			
		||||
	if cap(bs) >= length {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue