diff options
author | Erik Dubbelboer <erik@dubbelboer.com> | 2023-02-03 15:41:39 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-03 08:41:39 +0100 |
commit | 9d5a7bf7e3086d12e71b078da56128e1e324fe4a (patch) | |
tree | 67b51dbf8f0cbc9f4d0421b3d4c98d15bfb2778e /b2s_new.go | |
parent | docs: add http2curl (#1480) (diff) | |
download | fasthttp-9d5a7bf7e3086d12e71b078da56128e1e324fe4a.tar.gz fasthttp-9d5a7bf7e3086d12e71b078da56128e1e324fe4a.tar.bz2 fasthttp-9d5a7bf7e3086d12e71b078da56128e1e324fe4a.zip |
Add support for Go 1.20 (#1481)
Diffstat (limited to 'b2s_new.go')
-rw-r--r-- | b2s_new.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/b2s_new.go b/b2s_new.go new file mode 100644 index 0000000..2cbf5e3 --- /dev/null +++ b/b2s_new.go @@ -0,0 +1,16 @@ +//go:build go1.20 +// +build go1.20 + +package fasthttp + +import "unsafe" + +// b2s converts byte slice to a string without memory allocation. +// See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ . +func b2s(b []byte) string { + if len(b) == 0 { + return "" + } + + return unsafe.String(&b[0], len(b)) +} |