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 /s2b_old.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 's2b_old.go')
-rw-r--r-- | s2b_old.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/s2b_old.go b/s2b_old.go new file mode 100644 index 0000000..4cc141c --- /dev/null +++ b/s2b_old.go @@ -0,0 +1,24 @@ +//go:build !go1.20 +// +build !go1.20 + +package fasthttp + +import ( + "reflect" + "unsafe" +) + +// s2b converts string to a byte slice without memory allocation. +// +// Note it may break if string and/or slice header will change +// in the future go versions. +func s2b(s string) (b []byte) { + /* #nosec G103 */ + bh := (*reflect.SliceHeader)(unsafe.Pointer(&b)) + /* #nosec G103 */ + sh := (*reflect.StringHeader)(unsafe.Pointer(&s)) + bh.Data = sh.Data + bh.Cap = sh.Len + bh.Len = sh.Len + return b +} |