mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2026-05-21 13:26:29 +03:00
update phony, add mobile versions of util bytes functions that don't try to store anything
This commit is contained in:
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)
|
||||
}
|
||||
Reference in New Issue
Block a user