(untested) move unsafe string conversion to pkg

* fix invalid UDP f/e start when no workers provided
* add bench for entire server
This commit is contained in:
Lawrence, Rendall
2023-03-22 12:26:43 +03:00
parent b956811e40
commit 665899017e
13 changed files with 380 additions and 58 deletions

View File

@@ -0,0 +1,21 @@
// Package str2bytes provides fast, but unsafe functions to convert string to []byte
// or vice versa.
package str2bytes
import "unsafe"
// StringToBytes converts string to slice of bytes
// without allocation. Note, that returned slice
// must NOT be modified, since strings in Go are
// immutable.
// See unsafe.Slice.
func StringToBytes(s string) []byte {
return unsafe.Slice(unsafe.StringData(s), len(s))
}
// BytesToString converts slice of bytes to string
// without allocation.
// See unsafe.String
func BytesToString(b []byte) string {
return unsafe.String(unsafe.SliceData(b), len(b))
}