mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-14 15:56:44 +03:00
Drop support before go1.20 (#2022)
We still had old implementations of s2b and b2s that didn't require unsafe.StringData and unsafe.SliceData that were added in go1.20. Since we don't support go1.20 anymore we can drop these functions.
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
//go:build go1.20
|
||||
|
||||
package fasthttp
|
||||
|
||||
import "unsafe"
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
//go: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 .
|
||||
//
|
||||
// Note it may break if string and/or slice header will change
|
||||
// in the future go versions.
|
||||
func b2s(b []byte) string {
|
||||
return *(*string)(unsafe.Pointer(&b))
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
//go:build go1.20
|
||||
|
||||
package fasthttpadaptor
|
||||
|
||||
import "unsafe"
|
||||
@@ -1,14 +0,0 @@
|
||||
//go:build !go1.20
|
||||
|
||||
package fasthttpadaptor
|
||||
|
||||
import "unsafe"
|
||||
|
||||
// b2s converts byte slice to a string without memory allocation.
|
||||
// See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
|
||||
//
|
||||
// Note it may break if string and/or slice header will change
|
||||
// in the future go versions.
|
||||
func b2s(b []byte) string {
|
||||
return *(*string)(unsafe.Pointer(&b))
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
//go:build go1.20
|
||||
|
||||
package fasthttp
|
||||
|
||||
import "unsafe"
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
//go: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) {
|
||||
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||||
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
|
||||
bh.Data = sh.Data
|
||||
bh.Cap = sh.Len
|
||||
bh.Len = sh.Len
|
||||
return b
|
||||
}
|
||||
Reference in New Issue
Block a user